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

Method waitForTask

Libraries/Threading/ThreadPool.cpp:192–216  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

190}
191
192SC::Result SC::ThreadPool::waitForTask(Task& task)
193{
194 SC_TRY_MSG(numWorkerThreads > 0, "Cannot wait for tasks on an uninitialized threadpool");
195
196 // Function is entirely protected by the mutex
197 poolMutex.lock();
198 auto deferUnlock = MakeDeferred([this] { poolMutex.unlock(); });
199
200 for (;;)
201 {
202 if (task.threadPool == nullptr)
203 {
204 break; // The task being waited has been flagged as completed
205 }
206 if (taskHead != nullptr or numRunningTasks != 0)
207 {
208 taskCompleted.wait(poolMutex);
209 }
210 else
211 {
212 break; // all tasks have completed (including the task being waited)
213 }
214 }
215 return Result(true);
216}
217
218SC::Result SC::ThreadPool::queueTask(Task& task)
219{

Callers 4

testThreadPoolMethod · 0.80
operator()Method · 0.80
operator()Method · 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