MCPcopy Create free account
hub / github.com/abbeycode/UnrarKit / WaitDone

Method WaitDone

Libraries/unrar/threadpool.cpp:186–211  ·  view source on GitHub ↗

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.

Source from the content-addressed store, hash-verified

184// We assume that it is always called from main thread, when pool threads
185// are sleeping yet.
186void 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

Callers 4

ProcessRSMethod · 0.80
blake2sp_updateFunction · 0.80
RestoreMethod · 0.80
Unpack5MTMethod · 0.80

Calls 2

CWaitForSingleObjectFunction · 0.85
cpthread_cond_waitFunction · 0.85

Tested by

no test coverage detected