X-Git-Url: http://xvm.mit.edu/gitweb/invirt/third/libt4.git/blobdiff_plain/26ade07ab0e62b98b452fbbd18edba0450035e35..03b35a9a1bd1f583e32b27d260b223a0989d6c75:/rpc/rpc.h diff --git a/rpc/rpc.h b/rpc/rpc.h index b44c057..58e9381 100644 --- a/rpc/rpc.h +++ b/rpc/rpc.h @@ -11,23 +11,31 @@ #include "marshall_wrap.h" #include "connection.h" +using std::chrono::milliseconds; + namespace rpc { static constexpr milliseconds to_max{12000}; static constexpr milliseconds to_min{100}; } -template struct is_valid_call : false_type {}; +template +struct is_valid_call : false_type {}; template struct is_valid_call : true_type {}; -template struct is_valid_registration : false_type {}; +template +struct is_valid_registration : false_type {}; template -struct is_valid_registration::type...), S(R &, Args...)> : true_type {}; +struct is_valid_registration< + S(R &, typename std::decay::type...), + S(R &, Args...)> : true_type {}; template -struct is_valid_registration : is_valid_registration {}; +struct is_valid_registration< + P, + S(C::*)(R &, Args...)> : is_valid_registration {}; // rpc client endpoint. // manages a xid space per destination socket @@ -48,7 +56,7 @@ class rpcc : private connection_delegate { string *rep; int intret; bool done = false; - mutex m; + std::mutex m; cond c; }; @@ -65,17 +73,17 @@ class rpcc : private connection_delegate { shared_ptr chan_; - mutex m_; // protect insert/delete to calls[] - mutex chan_m_; + std::mutex m_; // protect insert/delete to calls[] + std::mutex chan_m_; bool destroy_wait_ = false; cond destroy_wait_c_; - map calls_; + std::map calls_; // xid starts with 1 and latest received reply starts with 0 xid_t xid_ = 1; - list xid_rep_window_ = {0}; + std::list xid_rep_window_ = {0}; struct request { void clear() { buf.clear(); xid = -1; } @@ -126,7 +134,7 @@ class rpcc : private connection_delegate { template inline int call_timeout(proc_t

proc, milliseconds to, R & r, const Args & ... args) { static_assert(is_valid_call::value, "RPC called with incorrect argument types"); - return call_m(proc.id, to, r, forward(marshall(args...))); + return call_m(proc.id, to, r, std::forward(marshall(args...))); } }; @@ -164,7 +172,7 @@ class rpcs : private connection_delegate { // provide at most once semantics by maintaining a window of replies // per client that that client hasn't acknowledged receiving yet. // indexed by client nonce. - map> reply_window_; + std::map> reply_window_; void add_reply(nonce_t clt_nonce, xid_t xid, const string & b); @@ -172,16 +180,16 @@ class rpcs : private connection_delegate { xid_t rep_xid, string & b); // latest connection to the client - map> conns_; + std::map> conns_; bool reachable_ = true; // map proc # to function - map procs_; + std::map procs_; - mutex procs_m_; // protect insert/delete to procs[] - mutex reply_window_m_; // protect reply window et al - mutex conns_m_; // protect conns_ + std::mutex procs_m_; // protect insert/delete to procs[] + std::mutex reply_window_m_; // protect reply window et al + std::mutex conns_m_; // protect conns_ void dispatch(shared_ptr c, const string & buf);