4#include "../Threading/Threading.h"
8struct SC_COMPILER_EXPORT ThreadPool;
61 Task* taskHead =
nullptr;
62 Task* taskTail =
nullptr;
64 size_t numRunningTasks = 0;
65 size_t numWorkerThreads = 0;
71 bool stopRequested =
false;
struct SC_COMPILER_EXPORT Function
Wraps function pointers, member functions and lambdas without ever allocating.
Definition Function.h:19
A native OS condition variable.
Definition Threading.h:58
A native OS mutex to synchronize access to shared resources.
Definition Threading.h:23
An ascii string used as boolean result. SC_TRY macro forwards errors to caller.
Definition Result.h:13
A small task containing a function to execute that can be queued in the thread pool.
Definition ThreadPool.h:16
Function< void()> function
Function that will be executed during the task.
Definition ThreadPool.h:18
Simple thread pool that executes tasks in a fixed number of worker threads.
Definition ThreadPool.h:38
Result destroy()
Destroy the thread pool created previously with ThreadPool::create.
Result queueTask(Task &task)
Queue a task (that should not be already in use)
Result waitForTask(Task &task)
Blocks execution until all queued and pending tasks will be fully completed.
Result create(size_t workerThreads)
Create a thread pool with the requested number of worker threads.
Result waitForAllTasks()
Blocks execution until all queued and pending tasks will be fully completed.