35 if (concurrentThreads <= 0)
38 if (concurrentThreads == -1)
184 bool workingThread =
false;
191 workingThread =
false;
211 workingThread =
true;
cbThreadedTask * m_pTask
a pointer to the running task
bool Aborted() const
Tells whether we should abort or not.
virtual int Execute()=0
Override this function with the task's job Return value doesn't matter.
A Thread Pool implementation.
int m_concurrentThreadsSchedule
cbThreadPool * m_pPool
point to the pool which the thread belong to
~cbThreadPool()
cbThreadPool dtor
bool WaitingThread()
Mechanism for the threads to tell the Pool they're done and will go to idle, so we can assign another...
void _SetConcurrentThreads(int concurrentThreads)
EVTIMPORT const wxEventType cbEVT_THREADTASK_ALLDONE
A generic Code::Blocks event.
WorkerThreadsArray m_threads
void wxPostEvent(wxEvtHandler *dest, const wxEvent &event)
cbThreadedTaskElement GetNextTask()
Returns the next task in the queue to run.
CountedPtr< wxSemaphore > m_semaphore
void BatchEnd()
End a batch process.
wxMutex m_taskMutex
to protect the member variable accessing from multiply threads lock the access to the m_pTask cbWorke...
CountedPtr< wxSemaphore > m_semaphore
a pointer to the wxSemaphore it is a counted semaphore pointer shared with all the cbWorkerThread ...
All tasks are added to one of these. It'll also save the autodelete value.
void SetConcurrentThreads(int concurrentThreads)
Changes the number of threads in the pool.
EVTIMPORT const wxEventType cbEVT_THREADTASK_ENDED
ExitCode Entry() override
Entry point of this thread. The magic happens here.
void Delete()
It'll delete the task only if it was set to.
void Abort()
Tell the thread to abort. It will also tell the task to abort (if any)
void Abort()
This function is called to tell the task to abort (check cbThreadPool::AbortAllTasks) ...
void TaskDone(cbWorkerThread *thread)
Called by a Worker Thread to inform a single task has finished, this will send a cbEVT_THREADTASK_END...
This is what you have to use instead of wxThread to add tasks to the Thread Pool. ...
void AbortTask()
Aborts the running task (if any)
cbWorkerThread(cbThreadPool *pool, CountedPtr< wxSemaphore > &semaphore)
cbWorkerThread ctor
void AddTask(cbThreadedTask *task, bool autodelete=true)
Adds a new task to the pool.
bool m_abort
whether is is aborted or not
int m_workingThreads
how many working threads are running tasks m_workingThreads + thread in Idle = m_concurrentThreads ...
friend class cbWorkerThread
void WorkingThread()
Mechanism for the threads to tell the Pool they're running, a thread is switch from the idle mode to ...
void AbortAllTasks()
Aborts all running and pending tasks.