35 #ifndef __CU_THREAD_POOL_H__
36 #define __CU_THREAD_POOL_H__
37 #include <cugl/base/CUBase.h>
39 #include <condition_variable>
46 #if defined (__WINDOWS__) || defined (__ANDROID__)
47 #define CU_SDL_THREADS 1
53 #pragma mark Thread Pool
79 std::vector<SDL_Thread*> _workers;
81 std::vector<std::thread> _workers;
85 std::queue< std::function<void()> > _taskQueue;
88 std::mutex _queueMutex;
90 std::condition_variable _taskCondition;
114 static int sdlThreadFunc(
void* ptr);
117 #pragma mark Constructors
160 virtual bool init(
int threads = 4);
163 #pragma mark Static Constructors
175 static std::shared_ptr<ThreadPool>
alloc(
int threads = 4) {
176 std::shared_ptr<ThreadPool> result = std::make_shared<ThreadPool>();
177 return (result->init(threads) ? result :
nullptr);
181 #pragma mark Task Management
192 void addTask(
const std::function<
void()> &task);
221 bool isShutdown()
const {
return _workers.size() == _complete; }
bool isStopped() const
Definition: CUThreadPool.h:212
bool isShutdown() const
Definition: CUThreadPool.h:221
static std::shared_ptr< ThreadPool > alloc(int threads=4)
Definition: CUThreadPool.h:175
void addTask(const std::function< void()> &task)
virtual bool init(int threads=4)
Definition: CUThreadPool.h:75
ThreadPool()
Definition: CUThreadPool.h:127
~ThreadPool()
Definition: CUThreadPool.h:137
Definition: CUAnimationNode.h:52