ONE - On-device Neural Engine
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
onert::exec::ThreadPool Class Reference

#include <ThreadPool.h>

Public Member Functions

 ThreadPool (uint32_t num_threads=1)
 Coustruct ThreadPool object.
 
 ~ThreadPool ()
 Destroy ThreadPool object.
 
void enqueue (std::unique_ptr< IFunction > &&fn)
 Enqueue a function.
 
uint32_t numJobsInQueue ()
 Get number of jobs in worker's queue.
 
void finish ()
 Block until all jobs are finished.
 

Detailed Description

Definition at line 29 of file ThreadPool.h.

Constructor & Destructor Documentation

◆ ThreadPool()

onert::exec::ThreadPool::ThreadPool ( uint32_t  num_threads = 1)

Coustruct ThreadPool object.

Parameters
num_threadsNumber of threads

Definition at line 24 of file ThreadPool.cc.

25{
26 assert(num_threads >= 1);
27
28 for (uint32_t i = 0; i < num_threads; i++)
29 {
30 _threads.emplace_back(std::ref(_worker));
31 }
32}

◆ ~ThreadPool()

onert::exec::ThreadPool::~ThreadPool ( )

Destroy ThreadPool object.

Definition at line 34 of file ThreadPool.cc.

35{
36 if (!_threads.empty())
37 {
38 _worker.terminate();
39 join();
40 }
41}
void terminate()
Flag as terminating so all the worker threads can terminate.
Definition WorkQueue.cc:77

References onert::exec::WorkQueue::terminate().

Member Function Documentation

◆ enqueue()

void onert::exec::ThreadPool::enqueue ( std::unique_ptr< IFunction > &&  fn)

Enqueue a function.

Parameters
fnA function to be queued

Definition at line 43 of file ThreadPool.cc.

43{ _worker.enqueue(std::move(fn)); }
void enqueue(std::unique_ptr< IFunction > &&fn)
Push the given Task to the job queue.
Definition WorkQueue.cc:68

References onert::exec::WorkQueue::enqueue().

◆ finish()

void onert::exec::ThreadPool::finish ( )

Block until all jobs are finished.

Definition at line 56 of file ThreadPool.cc.

57{
58 _worker.finish();
59 join();
60}
void finish()
Flag as terminating so all the worker threads can terminate.
Definition WorkQueue.cc:86

References onert::exec::WorkQueue::finish().

◆ numJobsInQueue()

uint32_t onert::exec::ThreadPool::numJobsInQueue ( )

Get number of jobs in worker's queue.

Returns
Number of jobs

Definition at line 45 of file ThreadPool.cc.

45{ return _worker.numJobsInQueue(); }
uint32_t numJobsInQueue()
Check if it has pending jobs. Even if this returns fals, WorkQueue threads may be still running.
Definition WorkQueue.cc:95

References onert::exec::WorkQueue::numJobsInQueue().


The documentation for this class was generated from the following files: