X-Git-Url: http://xvm.mit.edu/gitweb/invirt/third/libt4.git/blobdiff_plain/f2170465073de34adf89161d4287182b518352c4..869c0cc91d8f6b2bb80026616372d16450b64d9f:/lock_client.h diff --git a/lock_client.h b/lock_client.h index 541cc23..74f17a8 100644 --- a/lock_client.h +++ b/lock_client.h @@ -1,17 +1,15 @@ // lock client interface. #ifndef lock_client_h - #define lock_client_h #ifdef __cplusplus -#include +#include "types.h" #include "lock_protocol.h" -#include "rpc/rpc.h" -#include "lang/verify.h" #include "rpc/fifo.h" #include "rsm_client.h" +#include "maybe.h" class lock_release_user { public: @@ -19,16 +17,8 @@ class lock_release_user { virtual ~lock_release_user() {} }; -using std::string; -using std::thread; -using std::list; -using std::map; - -typedef string callback; - class lock_state { public: - lock_state(); enum { none = 0, retrying, @@ -36,40 +26,41 @@ public: locked, acquiring, releasing - } state; + } state = none; std::thread::id held_by; - list wanted_by; - mutex m; - map c; + std::list wanted_by; + std::mutex m; + std::map c; lock_protocol::xid_t xid; - void wait(); + void wait(lock & mutex_lock); void signal(); - void signal(std::thread::id who); + void signal(thread::id who); }; -typedef map lock_map; +typedef std::map lock_map; // Clients that caches locks. The server can revoke locks using // lock_revoke_server. class lock_client { private: - rpcc *cl; - std::thread releaser_thread; - rsm_client *rsmc; - class lock_release_user *lu; - unsigned int rlock_port; + unique_ptr cl; + unique_ptr rlsrpc; + thread releaser_thread; + unique_ptr rsmc; + lock_release_user *lu; + in_port_t rlock_port; string hostname; string id; - mutex xid_mutex; + std::mutex xid_mutex; lock_protocol::xid_t next_xid; - fifo release_fifo; - mutex lock_table_lock; + fifo> 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 unsigned int last_port; - lock_client(string xdst, class lock_release_user *l = 0); - ~lock_client() {} + static in_port_t last_port; + lock_client(string xdst, lock_release_user *l = 0); + ~lock_client(); lock_protocol::status acquire(lock_protocol::lockid_t); lock_protocol::status release(lock_protocol::lockid_t); int stat(lock_protocol::lockid_t); @@ -80,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; @@ -103,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