From: Peter Iannucci Date: Thu, 19 Dec 2013 04:07:13 +0000 (-0800) Subject: All sleep calls via std::this_thread X-Git-Url: http://xvm.mit.edu/gitweb/invirt/third/libt4.git/commitdiff_plain/ab6c1548ac2b1907bca92c8ce43e919c1a649a6f?ds=sidebyside All sleep calls via std::this_thread --- diff --git a/lock_smain.cc b/lock_smain.cc index ae3b51d..64f7985 100644 --- a/lock_smain.cc +++ b/lock_smain.cc @@ -1,8 +1,4 @@ #include "lock_server.h" -#include -#include - -// Main loop of lock_server int main(int argc, char *argv[]) { global = new t4_state('s'); @@ -20,5 +16,5 @@ int main(int argc, char *argv[]) { rsm.start(); while(1) - sleep(1000); + std::this_thread::sleep_for(milliseconds(1000)); } diff --git a/lock_tester.cc b/lock_tester.cc index 07961c7..fbdeeb4 100644 --- a/lock_tester.cc +++ b/lock_tester.cc @@ -65,7 +65,7 @@ static void test2(int i) { 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); diff --git a/rpc/rpc.cc b/rpc/rpc.cc index 5d28f8f..e6ec410 100644 --- a/rpc/rpc.cc +++ b/rpc/rpc.cc @@ -81,6 +81,8 @@ rpcc::rpcc(const string & d) : dst_(make_sockaddr(d)) 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); @@ -254,7 +256,7 @@ int rpcc::call1(proc_id_t proc, milliseconds to, string & rep, marshall & req) { << 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 & ch) { @@ -266,14 +268,9 @@ void rpcc::get_latest_connection(shared_ptr & 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 &, 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 &, const string & b) { unmarshall rep(b, true); rpc_protocol::reply_header h; rep.read_header(h); diff --git a/rpc/rpctest.cc b/rpc/rpctest.cc index 051e564..0435ab1 100644 --- a/rpc/rpctest.cc +++ b/rpc/rpctest.cc @@ -59,7 +59,8 @@ int srv::handle_fast(int & r, const int a) { } int srv::handle_slow(int & r, const int a) { - usleep(std::uniform_int_distribution(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; } @@ -420,5 +421,5 @@ int main(int argc, char *argv[]) { } while (1) - usleep(100000); + std::this_thread::sleep_for(milliseconds(100)); } diff --git a/rsm_client.cc b/rsm_client.cc index 9906d39..4a484ae 100644 --- a/rsm_client.cc +++ b/rsm_client.cc @@ -35,7 +35,7 @@ rsm_protocol::status rsm_client::invoke(unsigned int proc, string & rep, const s 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) {