| 227 | } |
| 228 | |
| 229 | void CWelsThreadPool::ExecuteTask() { |
| 230 | //fprintf(stdout, "ThreadPool: scheduled tasks: ExecuteTask\n"); |
| 231 | CWelsTaskThread* pThread = NULL; |
| 232 | IWelsTask* pTask = NULL; |
| 233 | while (GetWaitedTaskNum() > 0) { |
| 234 | //fprintf(stdout, "ThreadPool: ExecuteTask: waiting task %d\n", GetWaitedTaskNum()); |
| 235 | pThread = GetIdleThread(); |
| 236 | if (pThread == NULL) { |
| 237 | //fprintf(stdout, "ThreadPool: ExecuteTask: no IdleThread\n"); |
| 238 | |
| 239 | break; |
| 240 | } |
| 241 | pTask = GetWaitedTask(); |
| 242 | //fprintf(stdout, "ThreadPool: ExecuteTask = %x at thread %x\n", pTask, pThread); |
| 243 | if (pTask) { |
| 244 | pThread->SetTask (pTask); |
| 245 | } else { |
| 246 | AddThreadToIdleQueue (pThread); |
| 247 | } |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | WELS_THREAD_ERROR_CODE CWelsThreadPool::QueueTask (IWelsTask* pTask) { |
| 252 | CWelsAutoLock cLock (m_cLockPool); |