thread_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_NAMESPACEso both names resolve to the same namespace.Symbol-visibility attribute for the public onnx-light C++ API.
Defined as empty because onnx-light does not require explicit
__declspec(dllexport)or__attribute__((visibility("default")))annotations — visibility is controlled at the shared-library level. The macro is provided so that vendored ONNX headers that decorate their declarations withONNX_APIcompile without modification.Namespace alias so that ONNX C++ code (and consumers such as onnxruntime) that refers to the literal
onnxnamespace — rather than theONNX_NAMESPACEmacro — resolves to the onnx-light namespace. The standard onnx package lives innamespace onnx; onnx-light usesonnx_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 fromonnx.-
namespace utils
-
class ThreadPool#
- #include <thread_pool.h>
Thread pool used to parallelize delayed block loading.
Manages a fixed set of worker threads that pull jobs from a shared queue. Call Start() to launch workers, SubmitTask() to enqueue work, and Wait() to block until all submitted jobs have completed and the workers have stopped. The pool can be restarted by calling Start() again after Wait() returns. Clear() resets internal state when the pool is idle (not started).
Public Functions
-
ThreadPool()#
Initializes the thread pool in a stopped, idle state.
-
~ThreadPool()#
Destroys the thread pool by calling Wait().
Blocks until all pending jobs have finished executing, then stops and joins all worker threads. If the pool has already been stopped, this is a no-op.
-
void Start(int32_t num_threads)#
Starts the pool by launching worker threads.
- Parameters:
num_threads – Number of worker threads to create. Any negative value (for example
-1) is treated as a request to use the value returned bystd::thread::hardware_concurrency().
-
void SubmitTask(std::function<void()> &&job)#
Submits a callable job for asynchronous execution.
If no worker threads have been started, the job is queued and will be run inline when Wait() is called.
- Parameters:
job – Callable to execute.
-
void Wait()#
Blocks until all submitted jobs have finished executing, then stops and joins all worker threads.
If no workers were started, runs any queued jobs inline on the calling thread. After Wait() returns, the pool is in a stopped state and can be restarted with Start().
-
inline size_t GetThreadCount() const#
Returns the number of worker threads currently in the pool.
-
inline bool IsStarted() const#
Returns whether the pool has been started and workers are running.
Private Functions
-
void worker_thread()#
Entry point executed by each worker thread.
-
ThreadPool()#
-
class ThreadPool#
-
namespace utils