worker_pool.h#

namespace onnx_light

Alias that makes onnx-light headers compatible with code that references ONNX_LIGHT_NAMESPACE (the macro used in the standard onnx package).

Set to ONNX_LIGHT_NAMESPACE so both names resolve to the same namespace.

Symbol-visibility attribute for the public onnx-light C++ API.

Maps the upstream compatibility macro to onnx-light’s explicit proto ABI annotation. This keeps declarations from vendored ONNX headers visible when lib_onnx_proto uses hidden visibility by default.

Namespace alias so that ONNX C++ code (and consumers such as onnxruntime) that refers to the literal onnx namespace — rather than the ONNX_NAMESPACE macro — resolves to the onnx-light namespace. The standard onnx package lives in namespace onnx; onnx-light uses onnx_light (via ONNX_LIGHT_NAMESPACE), so this alias keeps onnx-light a true drop-in. It is only introduced when the onnx-light namespace differs from onnx.

namespace utils
class WorkerPool#
#include <worker_pool.h>

Persistent fixed-size worker pool.

Workers remain available across calls to WaitIdle() and stop only when Shutdown() is called.

Public Functions

WorkerPool()#
explicit WorkerPool(int32_t num_threads)#
~WorkerPool()#
WorkerPool(const WorkerPool&) = delete#
WorkerPool &operator=(const WorkerPool&) = delete#
void Start(int32_t num_threads)#

Starts persistent workers. A negative count uses hardware concurrency.

void Enqueue(std::function<void()> job)#

Enqueues work for execution.

void WaitIdle()#

Waits for all queued work and rethrows the first task exception.

void Shutdown()#

Drains pending work and permanently joins the current worker set.

size_t GetThreadCount() const#
bool IsStarted() const#

Private Functions

void Execute(std::function<void()> &job) noexcept#
void WorkerLoop()#
std::exception_ptr WaitIdleImpl(bool rethrow_exceptions)#
std::exception_ptr ShutdownAndTakeException() noexcept#

Private Members

std::vector<std::thread> workers_#
std::queue<std::function<void()>> jobs_#
mutable std::mutex mutex_#
std::condition_variable work_cv_#
std::condition_variable done_cv_#
bool stop_#
bool started_#
size_t pending_jobs_#
std::exception_ptr first_exception_#

Friends

friend class ThreadPool