bpf::system::ThreadPool class

Represents a thread pool

Constructors, destructors, conversion operators

ThreadPool(fsize tcount = 2, const String& name = "") explicit
ThreadPool(ThreadPool&& other) noexcept
~ThreadPool()

Public functions

auto operator=(ThreadPool&& other) -> ThreadPool& noexcept
void Run(std::function<Dynamic()> processing, std::function<void(Dynamic&)> callback)
void Run(std::function<void()> processing)
auto IsIdle() const -> bool
void Poll()

Function documentation

bpf::system::ThreadPool::ThreadPool(fsize tcount = 2, const String& name = "") explicit

Parameters
tcount maximum number of threads
name the name of the ThreadPool

Constructs a ThreadPool

bpf::system::ThreadPool::ThreadPool(ThreadPool&& other) noexcept

Move constructor

ThreadPool& bpf::system::ThreadPool::operator=(ThreadPool&& other) noexcept

Move assignment operator

void bpf::system::ThreadPool::Run(std::function<Dynamic()> processing, std::function<void(Dynamic&)> callback)

Parameters
processing the actual threaded function
callback function to call on completion on the thread Poll is called

Runs a task using this ThreadPool. Passing captures by reference is undefined in the processing function. Passing captures by pointer is undefined in the processing function. To pass references or pointers in the callback make sure these captures will not fall out of scope before the callback function returns

void bpf::system::ThreadPool::Run(std::function<void()> processing)

Parameters
processing the actual threaded function

Runs a task which does not produce any output Passing captures by reference is undefined in the processing function. Passing captures by pointer is undefined in the processing function.

bool bpf::system::ThreadPool::IsIdle() const

Returns true if this ThreadPool is idle, false otherwise

Checks if this ThreadPool is idle: it has no tasks anymore

void bpf::system::ThreadPool::Poll()

Call this function (usually on the main thread) in order to update the status of each task and run callbacks when needed. Calling this function from multiple threads is undefined behavior; always call this function from the same thread