-
Notifications
You must be signed in to change notification settings - Fork 3
/
lock_server.h
45 lines (29 loc) · 973 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
// this is the lock server
// the lock client has a similar interface
#ifndef lock_server_h
#define lock_server_h
#include <pthread.h>
#include <string>
#include "lock_protocol.h"
#include "lock_client.h"
#include "rpc.h"
#include <map>
class lock_server {
protected:
int nacquire;
// each lock is identified by an integer of type lock_protocol::lockit_t
// use std::map to hold the table of lock states
enum LockStatus { FREE, LOCKED };
typedef std::map<lock_protocol::lockid_t, LockStatus> LockToStatus;
LockToStatus lockToStatus;
// mutex for the global shared lock data for a server
pthread_mutex_t mutexLockMap;
pthread_cond_t lockAvailableCon;
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