#include "lock_server.h"
-#include <arpa/inet.h>
-#include <unistd.h>
-
-// Main loop of lock_server
int main(int argc, char *argv[]) {
global = new t4_state('s');
rsm.start();
while(1)
- sleep(1000);
+ std::this_thread::sleep_for(milliseconds(1000));
}
lc[i]->acquire(a);
LOG_NONMEMBER << "test2: client " << i << " acquire done";
check_grant(a);
- usleep(100000);
+ std::this_thread::sleep_for(milliseconds(100));
LOG_NONMEMBER << "test2: client " << i << " release";
check_release(a);
lc[i]->release(a);
rpcc::~rpcc() {
lock ml(m_);
cancel(ml);
+
+ lock cl(chan_m_);
IF_LEVEL(2) LOG << "delete nonce " << clt_nonce_ << " chan " << (chan_?(int)chan_->fd:-1);
chan_.reset();
VERIFY(calls_.size() == 0);
<< ntoh(dst_.sin_port) << " done? " << ca.done << " ret " << ca.intret;
// destruction of req automatically frees its buffer
- return (ca.done? ca.intret : rpc_protocol::timeout_failure);
+ return ca.done ? ca.intret : rpc_protocol::timeout_failure;
}
void rpcc::get_latest_connection(shared_ptr<connection> & ch) {
ch = chan_;
}
-// PollMgr's thread is being used to
-// make this upcall from connection object to rpcc.
-// this funtion must not block.
-//
-// this function keeps no reference for connection *c
-bool
-rpcc::got_pdu(const shared_ptr<connection> &, const string & b)
-{
+// Runs in poll_mgr's thread as an upcall from the connection object to the
+// rpcc. Does not call blocking RPC handlers.
+bool rpcc::got_pdu(const shared_ptr<connection> &, const string & b) {
unmarshall rep(b, true);
rpc_protocol::reply_header h;
rep.read_header(h);
}
int srv::handle_slow(int & r, const int a) {
- usleep(std::uniform_int_distribution<useconds_t>(0,500)(global->random_generator));
+ int us = std::uniform_int_distribution<>(0,500)(global->random_generator);
+ std::this_thread::sleep_for(microseconds(us));
r = a + 2;
return 0;
}
}
while (1)
- usleep(100000);
+ std::this_thread::sleep_for(milliseconds(100));
}
return rsm_protocol::OK;
if (ret == rsm_client_protocol::BUSY) {
LOG << "rsm is busy " << prim;
- usleep(300000);
+ std::this_thread::sleep_for(milliseconds(300));
continue;
}
if (ret == rsm_client_protocol::NOTPRIMARY) {