summaryrefslogtreecommitdiff
path: root/nest/locks.h
diff options
context:
space:
mode:
authorMartin Mares <mj@ucw.cz>1999-12-09 18:54:20 +0000
committerMartin Mares <mj@ucw.cz>1999-12-09 18:54:20 +0000
commitf545d38707bf01aa9db3915d782a547f89f92c1d (patch)
treeb5bb07889273603a91e63a52813e634540ddd877 /nest/locks.h
parent30bc402ebb324749f9468f8ff196545bb0a58442 (diff)
Added universal locking mechanism which will solve problems
with protocols wanting to use the same port on the same interface during reconfiguration time. How to use locks: In the if_notify hook, just order locks for the interfaces you want to work with and do the real socket opening after the lock hook function gets called. When you stop using the socket, close it and rfree() the lock. Please update your protocols to use the new locking mechanism.
Diffstat (limited to 'nest/locks.h')
-rw-r--r--nest/locks.h52
1 files changed, 52 insertions, 0 deletions
diff --git a/nest/locks.h b/nest/locks.h
new file mode 100644
index 00000000..e465bf55
--- /dev/null
+++ b/nest/locks.h
@@ -0,0 +1,52 @@
+/*
+ * BIRD Object Locks
+ *
+ * (c) 1999 Martin Mares <mj@ucw.cz>
+ *
+ * Can be freely distributed and used under the terms of the GNU GPL.
+ */
+
+#ifndef _BIRD_LOCKS_H_
+#define _BIRD_LOCKS_H_
+
+#include "lib/resource.h"
+#include "lib/event.h"
+
+/*
+ * The object locks are used for controlling exclusive access
+ * to various physical resources like UDP ports on specific devices.
+ * When you want to access such resource, you ask for a object lock
+ * structure, fill in specification of the object and your function
+ * you want to have called when the object is available and invoke
+ * olock_acquire() afterwards. When the object becomes free, the lock
+ * manager calls your function. To free the object lock, just call rfree
+ * on its resource.
+ */
+
+struct object_lock {
+ resource r;
+ ip_addr addr; /* Identification of a object: IP address */
+ unsigned int type; /* ... object type (OBJLOCK_xxx) */
+ struct iface *iface; /* ... interface */
+ unsigned int port; /* ... port number */
+ void (*hook)(struct object_lock *); /* Called when the lock succeeds */
+ void *data; /* User data */
+ /* ... internal to lock manager, don't touch ... */
+ node n; /* Node in list of olocks */
+ int state; /* OLOCK_STATE_xxx */
+ list waiters; /* Locks waiting for the same resource */
+};
+
+struct object_lock *olock_new(pool *);
+void olock_acquire(struct object_lock *);
+void olock_init(void);
+
+#define OBJLOCK_UDP 1 /* UDP port */
+#define OBJLOCK_TCP 2 /* TCP port */
+
+#define OLOCK_STATE_FREE 0
+#define OLOCK_STATE_LOCKED 1
+#define OLOCK_STATE_WAITING 2
+#define OLOCK_STATE_EVENT 3 /* waiting for unlock processing */
+
+#endif