X-Git-Url: http://xvm.mit.edu/gitweb/invirt/third/libt4.git/blobdiff_plain/02967a43024ce81912cd1ec96a800397457f8066:/lock_client.h..ab9eee5d7f1fbe7a3fe6229d4a78136efb14371b:/include/lock_client.h diff --git a/lock_client.h b/include/lock_client.h similarity index 63% rename from lock_client.h rename to include/lock_client.h index 9e449f4..64848b5 100644 --- a/lock_client.h +++ b/include/lock_client.h @@ -5,59 +5,50 @@ #ifdef __cplusplus -#include "types.h" -#include "lock_protocol.h" -#include "rpc/fifo.h" -#include "rsm_client.h" -#include "maybe.h" - -class lock_release_user { - public: - virtual void dorelease(lock_protocol::lockid_t) = 0; - virtual ~lock_release_user() {} -}; - -class lock_state { -public: - enum { - none = 0, - retrying, - free, - locked, - acquiring, - releasing - } state = none; - std::thread::id held_by; - std::list wanted_by; - std::mutex m; - std::map c; - lock_protocol::xid_t xid; - void wait(lock & mutex_lock); - void signal(); - void signal(thread::id who); -}; - -typedef std::map lock_map; +#include "include/types.h" +#include "include/lock_protocol.h" +#include "include/rpc/fifo.h" +#include "include/rsm_client.h" +#include "include/maybe.h" // Clients that caches locks. The server can revoke locks using // lock_revoke_server. class lock_client { private: + class lock_state { + public: + enum { + none = 0, + retrying, + free, + locked, + acquiring, + releasing + } state = none; + std::thread::id held_by; + std::list wanted_by; + std::mutex m; + std::map c; + lock_protocol::xid_t xid; + void wait(lock & mutex_lock); + void signal(); + void signal(thread::id who); + }; + unique_ptr rlsrpc; thread releaser_thread; unique_ptr rsmc; - lock_release_user *lu; in_port_t rlock_port; string hostname; string id; std::mutex xid_mutex; - lock_protocol::xid_t next_xid; + lock_protocol::xid_t next_xid=0; fifo> release_fifo; std::mutex lock_table_lock; - lock_map lock_table; + std::map lock_table; lock_state & get_lock_state(lock_protocol::lockid_t lid); public: - lock_client(string xdst, lock_release_user *l = 0); + lock_client(string xdst); ~lock_client(); lock_protocol::status acquire(lock_protocol::lockid_t); lock_protocol::status release(lock_protocol::lockid_t);