Add task to queue. We assume that it is always called from main thread, it allows to avoid any locks here. We process collected tasks only when WaitDone is called.
| 165 | // it allows to avoid any locks here. We process collected tasks only |
| 166 | // when WaitDone is called. |
| 167 | void ThreadPool::AddTask(PTHREAD_PROC Proc,void *Data) |
| 168 | { |
| 169 | if (ThreadsCreatedCount == 0) |
| 170 | CreateThreads(); |
| 171 | |
| 172 | // If queue is full, wait until it is empty. |
| 173 | if (ActiveThreads>=ASIZE(TaskQueue)) |
| 174 | WaitDone(); |
| 175 | |
| 176 | TaskQueue[QueueTop].Proc = Proc; |
| 177 | TaskQueue[QueueTop].Param = Data; |
| 178 | QueueTop = (QueueTop + 1) % ASIZE(TaskQueue); |
| 179 | ActiveThreads++; |
| 180 | } |
| 181 | |
| 182 | |
| 183 | // Start queued tasks and wait until all threads are inactive. |
no outgoing calls
no test coverage detected