From: Peter Iannucci Date: Thu, 19 Dec 2013 08:41:54 +0000 (-0800) Subject: Clean-ups X-Git-Url: http://xvm.mit.edu/gitweb/invirt/third/libt4.git/commitdiff_plain/c279db4240a3a3c30f069ab9dea8055cf94280da?ds=sidebyside Clean-ups --- diff --git a/Makefile b/Makefile index e41486f..caf3439 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ EXTRA_TARGETS ?= all: lock_demo lock_server lock_tester rsm_tester rpc/rpctest $(EXTRA_TARGETS) -rpc/librpc.a: rpc/rpc.o rpc/connection.o rpc/poll_mgr.o rpc/thr_pool.o +rpc/librpc.a: rpc/rpc.o rpc/connection.o rpc/poll_mgr.o rpc/thread_pool.o rm -f $@ ar cq $@ $^ ranlib rpc/librpc.a diff --git a/lock_client.cc b/lock_client.cc index e1bd62f..b29fff4 100644 --- a/lock_client.cc +++ b/lock_client.cc @@ -46,15 +46,7 @@ lock_client::~lock_client() { } void lock_client::releaser() { - while (1) { - maybe mlid; - release_fifo.deq(&mlid); - - if (!mlid) { - LOG << "Releaser stopping"; - break; - } - + while (auto mlid = release_fifo.deq()) { lock_protocol::lockid_t lid = mlid; LOG << "Releaser: " << lid; @@ -74,6 +66,7 @@ void lock_client::releaser() { LOG << "Lock " << lid << ": none"; st.signal(); } + LOG << "Releaser stopping"; } int lock_client::stat(lock_protocol::lockid_t lid) { diff --git a/lock_server.cc b/lock_server.cc index 141a598..efb23f5 100644 --- a/lock_server.cc +++ b/lock_server.cc @@ -39,8 +39,7 @@ lock_server::lock_server(rsm & r) : rsm_ (&r) { void lock_server::revoker () { while (1) { - lock_protocol::lockid_t lid; - revoke_fifo.deq(&lid); + lock_protocol::lockid_t lid = revoke_fifo.deq(); LOG << "Revoking " << lid; if (rsm_ && !rsm_->amiprimary()) continue; @@ -60,8 +59,7 @@ void lock_server::revoker () { void lock_server::retryer() { while (1) { - lock_protocol::lockid_t lid; - retry_fifo.deq(&lid); + lock_protocol::lockid_t lid = retry_fifo.deq(); if (rsm_ && !rsm_->amiprimary()) continue; diff --git a/rpc/fifo.h b/rpc/fifo.h index dfb4d05..9e4933a 100644 --- a/rpc/fifo.h +++ b/rpc/fifo.h @@ -3,7 +3,6 @@ #include "types.h" -// blocks enq() and deq() when queue is FULL or EMPTY template class fifo { public: @@ -21,19 +20,15 @@ class fifo { return true; } - void deq(T * e) { + T deq() { lock ml(m_); while(q_.empty()) non_empty_c_.wait(ml); - *e = q_.front(); + T t = q_.front(); q_.pop_front(); if (max_ && q_.size() < max_) has_space_c_.notify_one(); - } - - bool size() { - lock ml(m_); - return q_.size(); + return t; } private: diff --git a/rpc/rpc.h b/rpc/rpc.h index f1eb3bc..df5d89e 100644 --- a/rpc/rpc.h +++ b/rpc/rpc.h @@ -2,11 +2,9 @@ #define rpc_h #include "types.h" -#include -#include #include "rpc_protocol.h" -#include "thr_pool.h" +#include "thread_pool.h" #include "marshall.h" #include "marshall_wrap.h" #include "connection.h" @@ -203,7 +201,7 @@ class rpcs : private connection_delegate { void dispatch(shared_ptr c, const string & buf); - unique_ptr dispatchpool_{new thread_pool(6, false)}; + unique_ptr dispatchpool_{new thread_pool(6)}; unique_ptr listener_; // RPC handler for clients binding diff --git a/rpc/thr_pool.cc b/rpc/thr_pool.cc deleted file mode 100644 index fc7be3d..0000000 --- a/rpc/thr_pool.cc +++ /dev/null @@ -1,33 +0,0 @@ -#include "thr_pool.h" - -// if blocking, then addJob() blocks when queue is full -// otherwise, addJob() simply returns false when queue is full -thread_pool::thread_pool(size_t sz, bool blocking) -: nthreads_(sz),blockadd_(blocking),jobq_(100*sz) { - for (size_t i=0; i +#include #include "fifo.h" typedef std::function job_t; class thread_pool { public: - thread_pool(size_t sz, bool blocking=true); + thread_pool(size_t sz); ~thread_pool(); - bool addJob(const job_t & j); private: - size_t nthreads_; - bool blockadd_; - fifo jobq_; std::vector th_; - void do_worker(); };