38 void SetConcurrentThreads(
int concurrentThreads);
46 int GetConcurrentThreads()
const;
49 int GetId()
const {
return m_ID; }
104 explicit CountedPtr(T *p =
nullptr) : ptr(p), count(new long(1)) {}
131 T &operator * ()
const 136 T *operator -> ()
const 179 bool Aborted()
const;
214 autodelete(_autodelete)
275 void _SetConcurrentThreads(
int concurrentThreads);
301 void WorkingThread();
311 bool WaitingThread();
328 m_concurrentThreads(-1),
329 m_stackSize(stackSize),
330 m_concurrentThreadsSchedule(0),
374 std::size_t awakeThreadNumber = std::min<std::size_t>(
m_tasksQueue.size(),
376 for (std::size_t i = 0; i < awakeThreadNumber; ++i)
380 #endif //CBTHREADPOOL_H
cbThreadedTask * m_pTask
a pointer to the running task
bool Done() const
Tells if the pool has finished its job.
A Thread Pool implementation.
int m_concurrentThreadsSchedule
std::vector< cbWorkerThread * > WorkerThreadsArray
cbThreadedTaskElement(cbThreadedTask *_task=nullptr, bool _autodelete=false)
cbThreadPool * m_pPool
point to the pool which the thread belong to
WorkerThreadsArray m_threads
CountedPtr(const CountedPtr< T > &p)
CountedPtr< wxSemaphore > m_semaphore
wxMutex m_taskMutex
to protect the member variable accessing from multiply threads lock the access to the m_pTask cbWorke...
int GetConcurrentThreads() const
Gets the current number of threads in the pool.
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.
cbThreadPool(wxEvtHandler *owner, int id=-1, int concurrentThreads=-1, unsigned int stackSize=0)
cbThreadPool ctor
Josuttis' implementation of CountedPtr.
void SetConcurrentThreads(int concurrentThreads)
Changes the number of threads in the pool.
void Delete()
It'll delete the task only if it was set to.
int GetId() const
return the pool ID
This is what you have to use instead of wxThread to add tasks to the Thread Pool. ...
void BatchBegin()
Begin a batch process.
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 ...
std::list< cbThreadedTaskElement > TasksQueue
const wxString ptr(_T("*"))
void dispose()
decrease the counter, and if it get 0, destroy both counter and value