X-Git-Url: http://xvm.mit.edu/gitweb/invirt/third/libt4.git/blobdiff_plain/ba03b19875aa2e3586e49b10904563cdd3b91de0..f0dcb6b97d6d40f67698d1f71ac26970f1776f82:/lock_client.cc diff --git a/lock_client.cc b/lock_client.cc index 0b071f5..beca1cc 100644 --- a/lock_client.cc +++ b/lock_client.cc @@ -30,7 +30,7 @@ lock_state & lock_client::get_lock_state(lock_protocol::lockid_t lid) { } lock_client::lock_client(string xdst, lock_release_user *_lu) : lu(_lu), next_xid(0) { - cl = new rpcc(xdst); + cl = unique_ptr(new rpcc(xdst)); if (cl->bind() < 0) LOG("lock_client: call bind"); @@ -38,20 +38,21 @@ lock_client::lock_client(string xdst, lock_release_user *_lu) : lu(_lu), next_xi rlock_port = ((random()%32000) | (0x1 << 10)); id = "127.0.0.1:" + to_string(rlock_port); last_port = rlock_port; - rpcs *rlsrpc = new rpcs(rlock_port); + rlsrpc = unique_ptr(new rpcs(rlock_port)); rlsrpc->reg(rlock_protocol::revoke, &lock_client::revoke_handler, this); rlsrpc->reg(rlock_protocol::retry, &lock_client::retry_handler, this); - rsmc = new rsm_client(xdst); + rsmc = unique_ptr(new rsm_client(xdst)); releaser_thread = thread(&lock_client::releaser, this); + rlsrpc->start(); } -void lock_client::releaser() [[noreturn]] { +void lock_client::releaser() { while (1) { lock_protocol::lockid_t lid; release_fifo.deq(&lid); LOG("Releaser: " << lid); - lock_state &st = get_lock_state(lid); + lock_state & st = get_lock_state(lid); lock sl(st.m); VERIFY(st.state == lock_state::locked && st.held_by == releaser_thread.get_id()); st.state = lock_state::releasing; @@ -72,13 +73,13 @@ void lock_client::releaser() [[noreturn]] { int lock_client::stat(lock_protocol::lockid_t lid) { VERIFY(0); int r; - auto ret = (lock_protocol::status)cl->call(lock_protocol::stat, r, cl->id(), lid); + auto ret = (lock_protocol::status)cl->call(lock_protocol::stat, r, lid, id); VERIFY (ret == lock_protocol::OK); return r; } lock_protocol::status lock_client::acquire(lock_protocol::lockid_t lid) { - lock_state &st = get_lock_state(lid); + lock_state & st = get_lock_state(lid); lock sl(st.m); auto self = this_thread::get_id(); @@ -143,7 +144,7 @@ lock_protocol::status lock_client::acquire(lock_protocol::lockid_t lid) { } lock_protocol::status lock_client::release(lock_protocol::lockid_t lid) { - lock_state &st = get_lock_state(lid); + lock_state & st = get_lock_state(lid); lock sl(st.m); auto self = this_thread::get_id(); VERIFY(st.state == lock_state::locked && st.held_by == self); @@ -166,7 +167,7 @@ lock_protocol::status lock_client::release(lock_protocol::lockid_t lid) { rlock_protocol::status lock_client::revoke_handler(int &, lock_protocol::lockid_t lid, lock_protocol::xid_t xid) { LOG("Revoke handler " << lid << " " << xid); - lock_state &st = get_lock_state(lid); + lock_state & st = get_lock_state(lid); lock sl(st.m); if (st.state == lock_state::releasing || st.state == lock_state::none) @@ -188,7 +189,7 @@ rlock_protocol::status lock_client::revoke_handler(int &, lock_protocol::lockid_ } rlock_protocol::status lock_client::retry_handler(int &, lock_protocol::lockid_t lid, lock_protocol::xid_t) { - lock_state &st = get_lock_state(lid); + lock_state & st = get_lock_state(lid); lock sl(st.m); VERIFY(st.state == lock_state::acquiring); st.state = lock_state::retrying;