Major clean-ups. Migrating to C++11.
[invirt/third/libt4.git] / rpc / thr_pool.h
index 5095961..4427aee 100644 (file)
@@ -1,17 +1,15 @@
-#ifndef __THR_POOL__
-#define __THR_POOL__
+#ifndef thr_pool_h
+#define thr_pool_h
 
-#include <pthread.h>
 #include <vector>
+#include <thread>
 
 #include "fifo.h"
 
 class ThrPool {
-
-
        public:
                struct job_t {
-                       void *(*f)(void *); //function point
+                       void (*f)(void *); //function point
                        void *a; //function arguments
                };
 
@@ -23,18 +21,17 @@ class ThrPool {
                bool takeJob(job_t *j);
 
        private:
-               pthread_attr_t attr_;
                int nthreads_;
                bool blockadd_;
 
 
                fifo<job_t> jobq_;
-               std::vector<pthread_t> th_;
+               std::vector<std::thread> th_;
 
-               bool addJob(void *(*f)(void *), void *a);
+               bool addJob(void (*f)(void *), void *a);
 };
 
-       template <class C, class A> bool 
+template <class C, class A> bool 
 ThrPool::addObjJob(C *o, void (C::*m)(A), A a)
 {
 
@@ -43,14 +40,13 @@ ThrPool::addObjJob(C *o, void (C::*m)(A), A a)
                        C *o;
                        void (C::*m)(A a);
                        A a;
-                       static void *func(void *vvv) {
+                       static void func(void *vvv) {
                                objfunc_wrapper *x = (objfunc_wrapper*)vvv;
                                C *o = x->o;
                                void (C::*m)(A ) = x->m;
                                A a = x->a;
                                (o->*m)(a);
                                delete x;
-                               return 0;
                        }
        };