X-Git-Url: http://xvm.mit.edu/gitweb/invirt/third/libt4.git/blobdiff_plain/5fd8cc8409d0efadc07dfe8d6774ad9ff477663d..eeab3e6cade87c1fe0a5f3d93522e12ccb9ec2ab:/rpc/thr_pool.cc diff --git a/rpc/thr_pool.cc b/rpc/thr_pool.cc index f9f32fa..73f94f4 100644 --- a/rpc/thr_pool.cc +++ b/rpc/thr_pool.cc @@ -1,69 +1,42 @@ -#include "slock.h" #include "thr_pool.h" #include #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); - } - pthread_exit(NULL); -} - -//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) { - pthread_attr_init(&attr_); - pthread_attr_setstacksize(&attr_, 128<<10); - - for (int i = 0; i < sz; i++) { - pthread_t t; - VERIFY(pthread_create(&t, &attr_, do_worker, (void *)this) ==0); - th_.push_back(t); - } + for (int i=0; if!=NULL); + job_t j; + while (1) { + jobq_.deq(&j); + if (!j) + break; + j(); + } } -