X-Git-Url: http://xvm.mit.edu/gitweb/invirt/third/libt4.git/blobdiff_plain/5fd8cc8409d0efadc07dfe8d6774ad9ff477663d..06282fd37814c4a9d53bca089b048709b368f5b3:/lock_client.h diff --git a/lock_client.h b/lock_client.h index df22711..74f17a8 100644 --- a/lock_client.h +++ b/lock_client.h @@ -5,26 +5,75 @@ #ifdef __cplusplus -#include +#include "types.h" #include "lock_protocol.h" -#include "rpc.h" -#include +#include "rpc/fifo.h" +#include "rsm_client.h" +#include "maybe.h" -// Client interface to the lock server +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; + +// Clients that caches locks. The server can revoke locks using +// lock_revoke_server. class lock_client { - protected: - rpcc *cl; - public: - lock_client(std::string d); - virtual ~lock_client() {}; - virtual lock_protocol::status acquire(lock_protocol::lockid_t); - virtual lock_protocol::status release(lock_protocol::lockid_t); - virtual lock_protocol::status stat(lock_protocol::lockid_t); + private: + 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; + std::mutex xid_mutex; + lock_protocol::xid_t next_xid; + fifo> release_fifo; + std::mutex lock_table_lock; + lock_map lock_table; + 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_protocol::status acquire(lock_protocol::lockid_t); + lock_protocol::status release(lock_protocol::lockid_t); + int stat(lock_protocol::lockid_t); + void releaser(); + rlock_protocol::status revoke_handler(int &, lock_protocol::lockid_t, lock_protocol::xid_t); + rlock_protocol::status retry_handler(int &, lock_protocol::lockid_t, lock_protocol::xid_t); }; -#endif +#endif // C++ +#ifdef __cplusplus extern "C" { +#endif struct _t4_lock_client; typedef struct _t4_lock_client t4_lock_client; @@ -39,7 +88,7 @@ typedef enum { typedef int t4_status; -typedef unsigned long long t4_lockid_t; +typedef const char * t4_lockid_t; t4_lock_client *t4_lock_client_new(const char *dst); void t4_lock_client_delete(t4_lock_client *); @@ -47,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