该工作主要是无限的从线程池的工作队列中获取任务并执行,如果成功获取任务,则会将线程移进忙碌队列:
- TC_FunctorWrapperInterface *TC_ThreadPool:: get(ThreadWorker *ptw) {
- TC_FunctorWrapperInterface *pFunctorWrapper = NULL;
- if(! _jobqueue. pop_front(pFunctorWrapper, 1000)) {
- return NULL; }
- {
- Lock sync( _tmutex); _busthread. insert(ptw);
- } return pFunctorWrapper;
- }
执行完,移回工作线程队列:_tpool->idle( this);
- void TC_ThreadPool:: idle(ThreadWorker *ptw) {
- Lock sync( _tmutex); _busthread. erase(ptw);
- //无繁忙线程, 通知等待在线程池结束的线程醒过来
- if( _busthread. empty()) {
- _bAllDone = true; _tmutex.notifyAll();
- } }










