Rolled handle infrastructure into rpcc.
[invirt/third/libt4.git] / lock_client.h
index 728fbf7..74f17a8 100644 (file)
@@ -9,6 +9,7 @@
 #include "lock_protocol.h"
 #include "rpc/fifo.h"
 #include "rsm_client.h"
+#include "maybe.h"
 
 class lock_release_user {
     public:
@@ -26,17 +27,17 @@ public:
         acquiring,
         releasing
     } state = none;
-    thread::id held_by;
-    list<thread::id> wanted_by;
-    mutex m;
-    map<thread::id, cond> c;
+    std::thread::id held_by;
+    std::list<thread::id> wanted_by;
+    std::mutex m;
+    std::map<thread::id, cond> c;
     lock_protocol::xid_t xid;
     void wait(lock & mutex_lock);
     void signal();
     void signal(thread::id who);
 };
 
-typedef map<lock_protocol::lockid_t, lock_state> lock_map;
+typedef std::map<lock_protocol::lockid_t, lock_state> lock_map;
 
 // Clients that caches locks.  The server can revoke locks using
 // lock_revoke_server.
@@ -50,16 +51,16 @@ class lock_client {
         in_port_t rlock_port;
         string hostname;
         string id;
-        mutex xid_mutex;
+        std::mutex xid_mutex;
         lock_protocol::xid_t next_xid;
-        fifo<lock_protocol::lockid_t> release_fifo;
-        mutex lock_table_lock;
+        fifo<maybe<lock_protocol::lockid_t>> release_fifo;
+        std::mutex lock_table_lock;
         lock_map lock_table;
-        lock_state &get_lock_state(lock_protocol::lockid_t lid);
+        lock_state & get_lock_state(lock_protocol::lockid_t lid);
     public:
         static in_port_t last_port;
         lock_client(string xdst, lock_release_user *l = 0);
-        ~lock_client() {}
+        ~lock_client();
         lock_protocol::status acquire(lock_protocol::lockid_t);
         lock_protocol::status release(lock_protocol::lockid_t);
         int stat(lock_protocol::lockid_t);
@@ -70,7 +71,9 @@ class lock_client {
 
 #endif // C++
 
+#ifdef __cplusplus
 extern "C" {
+#endif
 
 struct _t4_lock_client;
 typedef struct _t4_lock_client t4_lock_client;
@@ -93,6 +96,8 @@ t4_status t4_lock_client_acquire(t4_lock_client *, t4_lockid_t);
 t4_status t4_lock_client_release(t4_lock_client *, t4_lockid_t);
 t4_status t4_lock_client_stat(t4_lock_client *, t4_lockid_t);
 
+#ifdef __cplusplus
 }
+#endif
 
 #endif