-int
-main(int argc, char *argv[])
-{
- setvbuf(stdout, NULL, _IONBF, 0);
- setvbuf(stderr, NULL, _IONBF, 0);
+lock_state & lock_server::get_lock_state(lock_protocol::lockid_t lid) {
+ lock sl(lock_table_lock);
+ // this will create the lock if it doesn't already exist
+ return lock_table[lid];
+}
+
+lock_server::lock_server(rsm & r) : rsm_ (&r) {
+ thread(&lock_server::revoker, this).detach();
+ thread(&lock_server::retryer, this).detach();
+ 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 () {
+ while (1) {
+ lock_protocol::lockid_t lid;
+ revoke_fifo.deq(&lid);
+ LOG("Revoking " << lid);
+ if (rsm_ && !rsm_->amiprimary())
+ continue;
+
+ lock_state & st = get_lock_state(lid);
+ holder_t held_by;
+ {
+ lock sl(st.m);
+ held_by = st.held_by;
+ }
+
+ rpcc *proxy = NULL;
+ // try a few times?
+ //int t=5;
+ //while (t-- && !proxy)
+ proxy = handle(held_by.first).safebind();
+ if (proxy) {
+ int r;
+ auto ret = (rlock_protocol::status)proxy->call(rlock_protocol::revoke, r, lid, held_by.second);
+ LOG("Revoke returned " << ret);
+ }
+ }
+}
+
+void lock_server::retryer() {
+ while (1) {
+ lock_protocol::lockid_t lid;
+ retry_fifo.deq(&lid);
+ if (rsm_ && !rsm_->amiprimary())
+ continue;