ONE - On-device Neural Engine
Loading...
Searching...
No Matches
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 31 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 26 of file ThreadPool.cc.

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

◆ ~ThreadPool()

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

Destroy ThreadPool object.

Definition at line 36 of file ThreadPool.cc.

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

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 45 of file ThreadPool.cc.

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

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

◆ finish()

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

Block until all jobs are finished.

Definition at line 58 of file ThreadPool.cc.

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

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 47 of file ThreadPool.cc.

47{ 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:97

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


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