MCPcopy Create free account
hub / github.com/Pagghiu/SaneCppLibraries / waitForAllTasks

Method waitForAllTasks

Libraries/Threading/ThreadPool.cpp:167–190  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

165}
166
167SC::Result SC::ThreadPool::waitForAllTasks()
168{
169 // Function is entirely protected by the mutex
170 poolMutex.lock();
171 auto deferUnlock = MakeDeferred([this] { poolMutex.unlock(); });
172 if (numWorkerThreads == 0)
173 {
174 return Result(true);
175 }
176 for (;;)
177 {
178 const bool runningWithPendingTasks = not stopRequested and (taskHead != nullptr or numRunningTasks != 0);
179 const bool stoppingWithRunningThreads = stopRequested and numWorkerThreads != 0;
180 if (runningWithPendingTasks or stoppingWithRunningThreads)
181 {
182 taskCompleted.wait(poolMutex);
183 }
184 else
185 {
186 break;
187 }
188 }
189 return Result(true);
190}
191
192SC::Result SC::ThreadPool::waitForTask(Task& task)
193{

Callers 1

testThreadPoolMethod · 0.80

Calls 5

MakeDeferredFunction · 0.85
ResultClass · 0.50
lockMethod · 0.45
unlockMethod · 0.45
waitMethod · 0.45

Tested by 1

testThreadPoolMethod · 0.64