// lock client interface.
#ifndef lock_client_h
-
#define lock_client_h
#ifdef __cplusplus
-#include <string>
+#include "types.h"
#include "lock_protocol.h"
-#include "rpc/rpc.h"
-#include "lang/verify.h"
#include "rpc/fifo.h"
#include "rsm_client.h"
virtual ~lock_release_user() {}
};
-using std::string;
-using std::thread;
-using std::list;
-using std::map;
-
-typedef string callback;
-
class lock_state {
public:
- lock_state();
enum {
none = 0,
retrying,
locked,
acquiring,
releasing
- } state;
- std::thread::id held_by;
- list<std::thread::id> wanted_by;
+ } state = none;
+ thread::id held_by;
+ list<thread::id> wanted_by;
mutex m;
- map<std::thread::id, std::condition_variable> c;
+ map<thread::id, cond> c;
lock_protocol::xid_t xid;
- void wait();
+ void wait(lock & mutex_lock);
void signal();
- void signal(std::thread::id who);
+ void signal(thread::id who);
};
typedef map<lock_protocol::lockid_t, lock_state> lock_map;
class lock_client {
private:
rpcc *cl;
- std::thread releaser_thread;
+ thread releaser_thread;
rsm_client *rsmc;
- class lock_release_user *lu;
- unsigned int rlock_port;
+ lock_release_user *lu;
+ in_port_t rlock_port;
string hostname;
string id;
mutex xid_mutex;
lock_map lock_table;
lock_state &get_lock_state(lock_protocol::lockid_t lid);
public:
- static unsigned int last_port;
- lock_client(string xdst, class lock_release_user *l = 0);
+ static in_port_t last_port;
+ lock_client(string xdst, lock_release_user *l = 0);
~lock_client() {}
lock_protocol::status acquire(lock_protocol::lockid_t);
lock_protocol::status release(lock_protocol::lockid_t);