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

Method queueTask

Libraries/Threading/ThreadPool.cpp:218–244  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

216}
217
218SC::Result SC::ThreadPool::queueTask(Task& task)
219{
220 SC_TRY_MSG(numWorkerThreads > 0, "Cannot queue tasks on an uninitialized threadpool");
221
222 // Function is entirely protected by the mutex
223 poolMutex.lock();
224 auto deferUnlock = MakeDeferred([this] { poolMutex.unlock(); });
225
226 SC_TRY_MSG(task.threadPool != this, "Trying to queue a task that has already been queued");
227 SC_TRY_MSG(task.threadPool == nullptr, "Trying to queue a task that is already in use by another threadpool");
228
229 task.threadPool = this;
230 if (taskHead == nullptr)
231 {
232 // FIFO was empty, replace head and tail with the task
233 taskHead = &task;
234 taskTail = taskHead;
235 }
236 else
237 {
238 // FIFO was not empty, append task to the tail
239 taskTail->next = &task;
240 taskTail = &task;
241 }
242 taskAvailable.broadcast();
243 return Result(true);
244}

Callers 4

testThreadPoolMethod · 0.80
testThreadPoolErrorsMethod · 0.80
operator()Method · 0.80

Calls 5

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

Tested by 3

testThreadPoolMethod · 0.64
testThreadPoolErrorsMethod · 0.64