Major clean-ups. Migrating to C++11.
[invirt/third/libt4.git] / lock_server.cc
1 // the lock server implementation
2
3 #include "lock_server.h"
4 #include <sstream>
5 #include <stdio.h>
6 #include <unistd.h>
7 #include <arpa/inet.h>
8 #include "lock.h"
9
10 lock_server::lock_server():
11     nacquire (0)
12 {
13 }
14
15 // caller must hold lock_lock
16 mutex &
17 lock_server::get_lock(lock_protocol::lockid_t lid) {
18     lock ml(lock_lock);
19     // by the semantics of std::map, this will create
20     // the mutex if it doesn't already exist
21     mutex &l = locks[lid];
22     return l;
23 }
24
25 lock_protocol::status
26 lock_server::stat(int clt, lock_protocol::lockid_t lid, int &r)
27 {
28     lock_protocol::status ret = lock_protocol::OK;
29     printf("stat request from clt %d\n", clt);
30     r = nacquire;
31     return ret;
32 }
33
34 lock_protocol::status
35 lock_server::acquire(int clt, lock_protocol::lockid_t lid, int &r)
36 {
37     get_lock(lid).lock();
38     return lock_protocol::OK;
39 }
40
41 lock_protocol::status
42 lock_server::release(int clt, lock_protocol::lockid_t lid, int &r)
43 {
44     get_lock(lid).unlock();
45     return lock_protocol::OK;
46 }