diff --git a/thread/threadpool.cpp b/thread/threadpool.cpp index 8da01601a9..593b309c09 100644 --- a/thread/threadpool.cpp +++ b/thread/threadpool.cpp @@ -3,7 +3,7 @@ ///////////////////////////// WorkerThread WorkerThread::WorkerThread() : active(true), started(false) { - thread = new std::thread(std::bind(&WorkerThread::WorkFunc, this)); + thread = new std::thread(bind(&WorkerThread::WorkFunc, this)); doneMutex.lock(); while(!started) { }; } @@ -17,7 +17,7 @@ WorkerThread::~WorkerThread() { delete thread; } -void WorkerThread::Process(const std::function& work) { +void WorkerThread::Process(const function& work) { mutex.lock(); work_ = work; signal.notify_one(); @@ -50,13 +50,17 @@ ThreadPool::ThreadPool(int numThreads) : numThreads(numThreads), workersStarted( void ThreadPool::StartWorkers() { if(!workersStarted) { for(int i=0; i()); +#ifdef __SYMBIAN32__ + workers.push_back(make_shared(weak_ptr())); +#else + workers.push_back(make_shared()); +#endif } workersStarted = true; } } -void ThreadPool::ParallelLoop(std::function loop, int lower, int upper) { +void ThreadPool::ParallelLoop(function loop, int lower, int upper) { mutex.lock(); StartWorkers(); int range = upper-lower; @@ -65,7 +69,7 @@ void ThreadPool::ParallelLoop(std::function loop, int lower, int // but doesn't matter since all our loops are power of 2 int chunk = range/numThreads; for(int s=lower, i=0; iProcess(std::bind(loop, s, std::min(s+chunk,upper))); + workers[i]->Process(bind(loop, s, std::min(s+chunk,upper))); } for(int i=0; iWaitForCompletion(); diff --git a/thread/threadpool.h b/thread/threadpool.h index 6f90073d8c..4bcddba33a 100644 --- a/thread/threadpool.h +++ b/thread/threadpool.h @@ -4,6 +4,14 @@ #include "base/mutex.h" #include +#ifdef __SYMBIAN32__ +#include +#include +#include +using namespace boost; +#else +using namespace std; +#endif #include // This is the simplest possible worker implementation I can think of @@ -15,7 +23,7 @@ public: ~WorkerThread(); // submit a new work item - void Process(const std::function& work); + void Process(const function& work); // wait for a submitted work item to be completed void WaitForCompletion(); @@ -25,7 +33,7 @@ private: condition_variable done; // used to signal work completion recursive_mutex mutex, doneMutex; // associated with each respective condition variable volatile bool active, started; - std::function work_; // the work to be done by this thread + function work_; // the work to be done by this thread void WorkFunc(); @@ -42,11 +50,11 @@ public: // don't need a destructor, "workers" is cleared on delete, // leading to the stopping and joining of all worker threads (RAII and all that) - void ParallelLoop(std::function loop, int lower, int upper); + void ParallelLoop(function loop, int lower, int upper); private: const int numThreads; - std::vector> workers; + std::vector> workers; recursive_mutex mutex; // used to sequentialize loop execution bool workersStarted;