Tkrzw
Classes | Public Types | Public Member Functions | List of all members
tkrzw::TaskQueue Class Referencefinal

Task queue with a thread pool. More...

#include <tkrzw_thread_util.h>

Classes

class  Task
 Interface of a task. More...
 
class  TaskWithLambda
 Task implementation with a lambda function. More...
 

Public Types

typedef std::function< void()> TaskLambdaType
 Lambda function type to do a task. More...
 

Public Member Functions

 TaskQueue ()
 Default constructor. More...
 
 ~TaskQueue ()
 Destructor. More...
 
void Start (int32_t num_worker_threads)
 Starts worker threads. More...
 
void Stop (double timeout)
 Stops worker threads. More...
 
void Add (std::unique_ptr< Task > task)
 Adds a task to the queue. More...
 
void Add (TaskLambdaType task)
 Adds a task to the queue. More...
 
int32_t GetSize ()
 Get the number of tasks in the queue. More...
 

Detailed Description

Task queue with a thread pool.

Member Typedef Documentation

◆ TaskLambdaType

typedef std::function<void()> tkrzw::TaskQueue::TaskLambdaType

Lambda function type to do a task.

Constructor & Destructor Documentation

◆ TaskQueue()

tkrzw::TaskQueue::TaskQueue ( )

Default constructor.

◆ ~TaskQueue()

tkrzw::TaskQueue::~TaskQueue ( )

Destructor.

Member Function Documentation

◆ Start()

void tkrzw::TaskQueue::Start ( int32_t  num_worker_threads)

Starts worker threads.

Parameters
num_worker_threadsThe number of worker threads.

◆ Stop()

void tkrzw::TaskQueue::Stop ( double  timeout)

Stops worker threads.

Parameters
timeoutThe timeout in seconds to wait for all tasks in the queue to be done.

◆ Add() [1/2]

void tkrzw::TaskQueue::Add ( std::unique_ptr< Task task)

Adds a task to the queue.

Parameters
taskThe task object.

◆ Add() [2/2]

void tkrzw::TaskQueue::Add ( TaskLambdaType  task)

Adds a task to the queue.

Parameters
taskThe lambda function to do the task.

◆ GetSize()

int32_t tkrzw::TaskQueue::GetSize ( )

Get the number of tasks in the queue.

Returns
The number of tasks in the queue.