Clean-ups to types.
[invirt/third/libt4.git] / lock_server.h
1 #ifndef lock_server_h
2 #define lock_server_h
3
4 #include "types.h"
5 #include "lock_protocol.h"
6 #include "rsm.h"
7 #include "rpc/fifo.h"
8
9 typedef string callback_t;
10 typedef pair<callback_t, lock_protocol::xid_t> holder_t;
11
12 class lock_state {
13 public:
14     lock_state();
15     lock_state(const lock_state &other);
16     bool held;
17     holder_t held_by;
18     list<holder_t> wanted_by;
19     map<callback_t, lock_protocol::xid_t> old_requests;
20     mutex m;
21     lock_state& operator=(const lock_state&);
22
23     MEMBERS(held, held_by, wanted_by)
24 };
25
26 MARSHALLABLE(lock_state)
27
28 typedef map<lock_protocol::lockid_t, lock_state> lock_map;
29
30 class lock_server : public rsm_state_transfer {
31     private:
32         int nacquire;
33         mutex lock_table_lock;
34         lock_map lock_table;
35         lock_state &get_lock_state(lock_protocol::lockid_t lid);
36         fifo<lock_protocol::lockid_t> retry_fifo;
37         fifo<lock_protocol::lockid_t> revoke_fifo;
38         rsm *rsm_;
39     public:
40         lock_server(rsm *r = 0);
41         lock_protocol::status stat(int &, lock_protocol::lockid_t);
42         void revoker();
43         void retryer();
44         string marshal_state();
45         void unmarshal_state(string state);
46         int acquire(int &, lock_protocol::lockid_t, string id, lock_protocol::xid_t);
47         int release(int &, lock_protocol::lockid_t, string id, lock_protocol::xid_t);
48 };
49
50 #endif