-
Notifications
You must be signed in to change notification settings - Fork 5
/
lock_server.h
42 lines (33 loc) · 858 Bytes
/
lock_server.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
// this is the lock server
// the lock client has a similar interface
#ifndef lock_server_h
#define lock_server_h
#include <string>
#include <map>
#include "lock_protocol.h"
#include "lock_client.h"
#include "rpc.h"
class lock_server {
protected:
enum lock_status {
free,
locked
};
struct lock_t {
int nacquire;
lock_status status;
pthread_cond_t free_c;
lock_t() : nacquire(0), status(lock_status::free) {
pthread_cond_init(&free_c, NULL);
}
};
pthread_mutex_t m;
std::map<lock_protocol::lockid_t, lock_t> locks;
public:
lock_server();
~lock_server() { }
lock_protocol::status stat(int clt, lock_protocol::lockid_t lid, int &);
lock_protocol::status acquire(int clt, lock_protocol::lockid_t lid, int &);
lock_protocol::status release(int clt, lock_protocol::lockid_t lid, int &);
};
#endif