X-Git-Url: http://xvm.mit.edu/gitweb/invirt/third/libt4.git/blobdiff_plain/a4175b2e216a20b86cc872dea8a08005c60617a5..dfe8486473094c0769fd1922329c3f0dfd8f43c0:/rpc/thr_pool.cc?ds=sidebyside diff --git a/rpc/thr_pool.cc b/rpc/thr_pool.cc index 26226cd..146764f 100644 --- a/rpc/thr_pool.cc +++ b/rpc/thr_pool.cc @@ -3,58 +3,40 @@ #include #include "lang/verify.h" -static void -do_worker(void *arg) -{ - ThrPool *tp = (ThrPool *)arg; - while (1) { - ThrPool::job_t j; - if (!tp->takeJob(&j)) - break; //die - - (void)(j.f)(j.a); - } -} - -//if blocking, then addJob() blocks when queue is full -//otherwise, addJob() simply returns false when queue is full +// if blocking, then addJob() blocks when queue is full +// otherwise, addJob() simply returns false when queue is full ThrPool::ThrPool(int sz, bool blocking) : nthreads_(sz),blockadd_(blocking),jobq_(100*sz) { - for (int i = 0; i < sz; i++) { - th_.push_back(std::thread(do_worker, this)); - } + for (int i=0; if!=NULL); + job_t j; + while (1) { + jobq_.deq(&j); + if (!j) + break; + j(); + } } -