Cosmetic improvements.
[invirt/third/libt4.git] / lock_server.cc
index 0c3a6e9..90ad5b2 100644 (file)
@@ -10,11 +10,11 @@ lock_state::lock_state():
 {
 }
 
 {
 }
 
-lock_state::lock_state(const lock_state &other) {
+lock_state::lock_state(const lock_state & other) {
     *this = other;
 }
 
     *this = other;
 }
 
-lock_state& lock_state::operator=(const lock_state& o) {
+lock_state & lock_state::operator=(const lock_state & o) {
     held = o.held;
     held_by = o.held_by;
     wanted_by = o.wanted_by;
     held = o.held;
     held_by = o.held_by;
     wanted_by = o.wanted_by;
@@ -28,10 +28,14 @@ lock_state & lock_server::get_lock_state(lock_protocol::lockid_t lid) {
     return lock_table[lid];
 }
 
     return lock_table[lid];
 }
 
-lock_server::lock_server(rsm *r) : rsm_ (r) {
+lock_server::lock_server(rsm & r) : rsm_ (&r) {
     thread(&lock_server::revoker, this).detach();
     thread(&lock_server::retryer, this).detach();
     thread(&lock_server::revoker, this).detach();
     thread(&lock_server::retryer, this).detach();
-    rsm_->set_state_transfer(this);
+    r.set_state_transfer(this);
+
+    r.reg(lock_protocol::acquire, &lock_server::acquire, this);
+    r.reg(lock_protocol::release, &lock_server::release, this);
+    r.reg(lock_protocol::stat, &lock_server::stat, this);
 }
 
 void lock_server::revoker () {
 }
 
 void lock_server::revoker () {
@@ -42,7 +46,7 @@ void lock_server::revoker () {
         if (rsm_ && !rsm_->amiprimary())
             continue;
 
         if (rsm_ && !rsm_->amiprimary())
             continue;
 
-        lock_state &st = get_lock_state(lid);
+        lock_state & st = get_lock_state(lid);
         holder_t held_by;
         {
             lock sl(st.m);
         holder_t held_by;
         {
             lock sl(st.m);
@@ -70,7 +74,7 @@ void lock_server::retryer() {
             continue;
 
         LOG("Sending retry for " << lid);
             continue;
 
         LOG("Sending retry for " << lid);
-        lock_state &st = get_lock_state(lid);
+        lock_state & st = get_lock_state(lid);
         holder_t front;
         {
             lock sl(st.m);
         holder_t front;
         {
             lock sl(st.m);
@@ -95,7 +99,7 @@ void lock_server::retryer() {
 lock_protocol::status lock_server::acquire(int &, lock_protocol::lockid_t lid, const callback_t & id, lock_protocol::xid_t xid) {
     LOG("lid=" << lid << " client=" << id << "," << xid);
     holder_t h = holder_t(id, xid);
 lock_protocol::status lock_server::acquire(int &, lock_protocol::lockid_t lid, const callback_t & id, lock_protocol::xid_t xid) {
     LOG("lid=" << lid << " client=" << id << "," << xid);
     holder_t h = holder_t(id, xid);
-    lock_state &st = get_lock_state(lid);
+    lock_state & st = get_lock_state(lid);
     lock sl(st.m);
 
     // deal with duplicated requests
     lock sl(st.m);
 
     // deal with duplicated requests
@@ -152,7 +156,7 @@ lock_protocol::status lock_server::acquire(int &, lock_protocol::lockid_t lid, c
 
 lock_protocol::status lock_server::release(int &, lock_protocol::lockid_t lid, const callback_t & id, lock_protocol::xid_t xid) {
     LOG("lid=" << lid << " client=" << id << "," << xid);
 
 lock_protocol::status lock_server::release(int &, lock_protocol::lockid_t lid, const callback_t & id, lock_protocol::xid_t xid) {
     LOG("lid=" << lid << " client=" << id << "," << xid);
-    lock_state &st = get_lock_state(lid);
+    lock_state & st = get_lock_state(lid);
     lock sl(st.m);
     if (st.held && st.held_by == holder_t(id, xid)) {
         st.held = false;
     lock sl(st.m);
     if (st.held && st.held_by == holder_t(id, xid)) {
         st.held = false;
@@ -165,18 +169,15 @@ lock_protocol::status lock_server::release(int &, lock_protocol::lockid_t lid, c
 
 string lock_server::marshal_state() {
     lock sl(lock_table_lock);
 
 string lock_server::marshal_state() {
     lock sl(lock_table_lock);
-    marshall rep;
-    rep << nacquire << lock_table;
-    return rep.content();
+    return marshall(nacquire, lock_table).content();
 }
 
 void lock_server::unmarshal_state(const string & state) {
     lock sl(lock_table_lock);
 }
 
 void lock_server::unmarshal_state(const string & state) {
     lock sl(lock_table_lock);
-    unmarshall rep(state, false);
-    rep >> nacquire >> lock_table;
+    unmarshall(state, false, nacquire, lock_table);
 }
 
 }
 
-lock_protocol::status lock_server::stat(int &r, lock_protocol::lockid_t lid, const callback_t &) {
+lock_protocol::status lock_server::stat(int & r, lock_protocol::lockid_t lid, const callback_t &) {
     LOG("stat request for " << lid);
     VERIFY(0);
     r = nacquire;
     LOG("stat request for " << lid);
     VERIFY(0);
     r = nacquire;