Major clean-ups. Migrating to C++11.
[invirt/third/libt4.git] / rpc / thr_pool.cc
index f9f32fa..26226cd 100644 (file)
@@ -1,10 +1,9 @@
-#include "slock.h"
 #include "thr_pool.h"
 #include <stdlib.h>
 #include <errno.h>
 #include "lang/verify.h"
 
-static void *
+static void
 do_worker(void *arg)
 {
        ThrPool *tp = (ThrPool *)arg;
@@ -15,7 +14,6 @@ do_worker(void *arg)
 
                (void)(j.f)(j.a);
        }
-       pthread_exit(NULL);
 }
 
 //if blocking, then addJob() blocks when queue is full
@@ -23,13 +21,8 @@ do_worker(void *arg)
 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);
+        th_.push_back(std::thread(do_worker, this));
        }
 }
 
@@ -39,19 +32,17 @@ ThrPool::~ThrPool()
 {
        for (int i = 0; i < nthreads_; i++) {
                job_t j;
-               j.f = (void *(*)(void *))NULL; //poison pill to tell worker threads to exit
+               j.f = (void (*)(void *))NULL; //poison pill to tell worker threads to exit
                jobq_.enq(j);
        }
 
        for (int i = 0; i < nthreads_; i++) {
-               VERIFY(pthread_join(th_[i], NULL)==0);
+        th_[i].join();
        }
-
-       VERIFY(pthread_attr_destroy(&attr_)==0);
 }
 
 bool 
-ThrPool::addJob(void *(*f)(void *), void *a)
+ThrPool::addJob(void (*f)(void *), void *a)
 {
        job_t j;
        j.f = f;