iof-bird-daemon / nest / locks.h @ a7a7372a
History | View | Annotate | Download (1.66 KB)
1 |
/*
|
---|---|
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 |
uint type; /* ... object type (OBJLOCK_xxx) */
|
30 |
uint port; /* ... port number */
|
31 |
uint inst; /* ... instance ID */
|
32 |
struct iface *iface; /* ... interface */ |
33 |
void (*hook)(struct object_lock *); /* Called when the lock succeeds */ |
34 |
void *data; /* User data */ |
35 |
/* ... internal to lock manager, don't touch ... */
|
36 |
node n; /* Node in list of olocks */
|
37 |
int state; /* OLOCK_STATE_xxx */ |
38 |
list waiters; /* Locks waiting for the same resource */
|
39 |
}; |
40 |
|
41 |
struct object_lock *olock_new(pool *);
|
42 |
void olock_acquire(struct object_lock *); |
43 |
void olock_init(void); |
44 |
|
45 |
#define OBJLOCK_UDP 1 /* UDP port */ |
46 |
#define OBJLOCK_TCP 2 /* TCP port */ |
47 |
#define OBJLOCK_IP 3 /* IP protocol */ |
48 |
|
49 |
#define OLOCK_STATE_FREE 0 |
50 |
#define OLOCK_STATE_LOCKED 1 |
51 |
#define OLOCK_STATE_WAITING 2 |
52 |
#define OLOCK_STATE_EVENT 3 /* waiting for unlock processing */ |
53 |
|
54 |
#endif
|