So many changes. Broken.
[invirt/third/libt4.git] / include / lock_server.h
1 #ifndef lock_server_h
2 #define lock_server_h
3
4 #include "include/types.h"
5 #include "include/lock_protocol.h"
6 #include "include/rsm.h"
7 #include "include/rpc/fifo.h"
8
9 class lock_server : private rsm_state_transfer {
10     private:
11         using holder_t=std::pair<callback_t, lock_protocol::xid_t>;
12
13         struct lock_state {
14             inline lock_state() {}
15             lock_state(const lock_state & other);
16             bool held=false;
17             holder_t held_by;
18             std::list<holder_t> wanted_by;
19             std::map<callback_t, lock_protocol::xid_t> old_requests;
20             std::mutex m;
21
22             MEMBERS(held, held_by, wanted_by)
23         };
24
25         int nacquire;
26         std::mutex lock_table_lock;
27         std::map<lock_protocol::lockid_t, lock_state> lock_table;
28         lock_state & get_lock_state(lock_protocol::lockid_t lid);
29         fifo<lock_protocol::lockid_t> retry_fifo, revoke_fifo;
30         rsm *rsm_;
31         string marshall_state();
32         void unmarshall_state(const string & state);
33         void revoker NORETURN ();
34         void retryer NORETURN ();
35     public:
36         lock_server(rsm & r);
37         lock_protocol::status acquire(int &, lock_protocol::lockid_t, const callback_t & id, lock_protocol::xid_t);
38         lock_protocol::status release(int &, lock_protocol::lockid_t, const callback_t & id, lock_protocol::xid_t);
39 };
40
41 #endif