-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlock_server_cache.h
99 lines (81 loc) · 2.11 KB
/
lock_server_cache.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#ifndef lock_server_cache_h
#define lock_server_cache_h
#include <string>
#include "lock_protocol.h"
#include "rpc.h"
#include "rsm_state_transfer.h"
#include "lock_server.h"
#include "fifo.h"
#include <stdio.h>
#include "rpc/fifo.h"
#include <map>
#include "rsm.h"
typedef enum {
LOCKED, REVOKING, RETRYING
} lock_status_;
typedef struct {
std::string client_address;
lock_protocol::lockid_t lockid;
int seq_number;
} client_info;
struct lock_t {
lock_status_ status;
client_info current;
client_info next;
pthread_mutex_t entry_lock;
std::vector<client_info> waiting_queue;
lock_t() {
pthread_mutex_init(&entry_lock, NULL);
}
};
class lock_server_cache : public rsm_state_transfer {
private:
class rsm *rsm;
public:
lock_server_cache(class rsm *rsm = 0);
lock_protocol::status stat(lock_protocol::lockid_t, int &);
lock_protocol::status acquire(std::string clt, lock_protocol::lockid_t lid, int &);
lock_protocol::status release(std::string clt, lock_protocol::lockid_t lid, int &);
void revoker();
void retryer();
std::string marshal_state();
void unmarshal_state(std::string);
};
inline marshall &operator<<(marshall &m, client_info c) {
m << c.client_address;
m << c.lockid;
m << c.seq_number;
return m;
}
inline unmarshall &operator>>(unmarshall &u, client_info &c) {
u >> c.client_address;
u >> c.lockid;
u >> c.seq_number;
return u;
}
/*
inline marshall &operator<<(marshall &m, fifo<client_info> q) {
client_info c;
m << q.size();
printf("MARSHALL FIFO S=%d\n", q.size());
for (; q.size() > 0;) {
q.deq(&c);
m << c;
}
return m;
}
inline unmarshall &operator>>(unmarshall &m, fifo<client_info> &q) {
int size;
client_info c;
m >> size;
printf("UNMARSHALL FIFO S=%d\n", size);
for (int i = 0; i < size; ++i) {
m >> c;
printf("UNMARSHALL FIFO LID=%lld\n", c.lockid);
printf("UNMARSHALL FIFO CLID=%s\n", c.client_address.c_str());
printf("UNMARSHALL FIFO SEQ=%d\n", c.seq_number);
q.enq(c);
}
return m;
}*/
#endif