Statistics
| Branch: | Revision:

iof-bird-daemon / nest / locks.h @ 7e95c05d

History | View | Annotate | Download (1.63 KB)

1 f545d387 Martin Mares
/*
2
 *        BIRD Object Locks
3
 *
4
 *        (c) 1999 Martin Mares <mj@ucw.cz>
5
 *
6
 *        Can be freely distributed and used under the terms of the GNU GPL.
7
 */
8
9
#ifndef _BIRD_LOCKS_H_
10
#define _BIRD_LOCKS_H_
11
12
#include "lib/resource.h"
13
#include "lib/event.h"
14
15
/*
16
 *  The object locks are used for controlling exclusive access
17
 *  to various physical resources like UDP ports on specific devices.
18
 *  When you want to access such resource, you ask for a object lock
19
 *  structure, fill in specification of the object and your function
20
 *  you want to have called when the object is available and invoke
21
 *  olock_acquire() afterwards. When the object becomes free, the lock
22
 *  manager calls your function. To free the object lock, just call rfree
23
 *  on its resource.
24
 */
25
26
struct object_lock {
27
  resource r;
28
  ip_addr addr;                /* Identification of a object: IP address */
29
  unsigned int type;        /* ... object type (OBJLOCK_xxx) */
30
  struct iface *iface;        /* ... interface */
31
  unsigned int port;        /* ... port number */
32
  void (*hook)(struct object_lock *);        /* Called when the lock succeeds */
33
  void *data;                /* User data */
34
  /* ... internal to lock manager, don't touch ... */
35
  node n;                /* Node in list of olocks */
36
  int state;                /* OLOCK_STATE_xxx */
37
  list waiters;                /* Locks waiting for the same resource */
38
};
39
40
struct object_lock *olock_new(pool *);
41
void olock_acquire(struct object_lock *);
42
void olock_init(void);
43
44
#define OBJLOCK_UDP 1                        /* UDP port */
45
#define OBJLOCK_TCP 2                        /* TCP port */
46 41ad16e2 Ondrej Filip
#define OBJLOCK_IP 3                        /* IP protocol */
47 f545d387 Martin Mares
48
#define OLOCK_STATE_FREE 0
49
#define OLOCK_STATE_LOCKED 1
50
#define OLOCK_STATE_WAITING 2
51
#define OLOCK_STATE_EVENT 3                /* waiting for unlock processing */
52
53
#endif