Start queued tasks and wait until all threads are inactive. We assume that it is always called from main thread, when pool threads are sleeping yet.
| 184 | // We assume that it is always called from main thread, when pool threads |
| 185 | // are sleeping yet. |
| 186 | void ThreadPool::WaitDone() |
| 187 | { |
| 188 | if (ActiveThreads==0) |
| 189 | return; |
| 190 | #ifdef _WIN_ALL |
| 191 | ResetEvent(NoneActive); |
| 192 | ReleaseSemaphore(QueuedTasksCnt,ActiveThreads,NULL); |
| 193 | CWaitForSingleObject(NoneActive); |
| 194 | #elif defined(_UNIX) |
| 195 | AnyActive=true; |
| 196 | |
| 197 | // Threads reset AnyActive before accessing QueuedTasksCnt and even |
| 198 | // preceding WaitDone() call does not guarantee that some slow thread |
| 199 | // is not accessing QueuedTasksCnt now. So lock is necessary. |
| 200 | pthread_mutex_lock(&QueuedTasksCntMutex); |
| 201 | QueuedTasksCnt+=ActiveThreads; |
| 202 | pthread_mutex_unlock(&QueuedTasksCntMutex); |
| 203 | |
| 204 | pthread_cond_broadcast(&QueuedTasksCntCond); |
| 205 | |
| 206 | pthread_mutex_lock(&AnyActiveMutex); |
| 207 | while (AnyActive) |
| 208 | cpthread_cond_wait(&AnyActiveCond,&AnyActiveMutex); |
| 209 | pthread_mutex_unlock(&AnyActiveMutex); |
| 210 | #endif |
| 211 | } |
| 212 | #endif // RAR_SMP |
no test coverage detected