Robot Raconteur Core C++ Library
Loading...
Searching...
No Matches
RobotRaconteur::IOContextThreadPool Class Reference

Thread pool for use with an external boost::asio::io_context and thread pool. More...

#include <ThreadPool.h>

Inheritance diagram for RobotRaconteur::IOContextThreadPool:
RobotRaconteur::ThreadPool

Public Member Functions

 IOContextThreadPool (const boost::shared_ptr< RobotRaconteurNode > &node, boost::asio::io_context &external_io_context, bool multithreaded)
 Construct an IOContextThreadPool.
RR_OVIRTUAL size_t GetThreadPoolCount () RR_OVERRIDE
 Returns 1 if single threaded, 2 if multithreaded.
RR_OVIRTUAL void SetThreadPoolCount (size_t count) RR_OVERRIDE
 Invalid for IOContextThreadPool, throws InvalidOperationException.
RR_OVIRTUAL void Post (boost::function< void()> function) RR_OVERRIDE
 Post a function to be executed by the thread pool in a worker thread and return immediately.
RR_OVIRTUAL bool TryPost (boost::function< void()> function) RR_OVERRIDE
 Try posting a function to be executed by the thread pool in a worker thread and return immediately.
RR_OVIRTUAL boost::asio::io_context & get_io_context () RR_OVERRIDE
 Get the boost::asio::io_context object.

Detailed Description

Thread pool for use with an external boost::asio::io_context and thread pool.

Users may need to integrate Robot Raconteur with an external thread pool, single threaded environment, or an existing boost::asio::io_context. The IOContextThreadPool allows the use of the external thread pool. See threading for more information on the use of threading.

The IOContextThreadPool is used either with a thread pool or a single thread. If used with a single thread, the multithreaded argument in the constructor must be false. Blocking functions may not be used when in single threaded operation.

Constructor & Destructor Documentation

◆ IOContextThreadPool()

RobotRaconteur::IOContextThreadPool::IOContextThreadPool ( const boost::shared_ptr< RobotRaconteurNode > & node,
boost::asio::io_context & external_io_context,
bool multithreaded )

Construct an IOContextThreadPool.

Must use boost::make_shared<IOContextThreadpool>()

Parameters
nodeThe node that owns the thread pool
external_io_context
multithreaded

Member Function Documentation

◆ get_io_context()

RR_OVIRTUAL boost::asio::io_context & RobotRaconteur::IOContextThreadPool::get_io_context ( )
virtual

Get the boost::asio::io_context object.

Use the returned boost::asio::io_context reference to initialize Boost.Asio objects

Returns
boost::asio::io_context&

Reimplemented from RobotRaconteur::ThreadPool.

◆ GetThreadPoolCount()

RR_OVIRTUAL size_t RobotRaconteur::IOContextThreadPool::GetThreadPoolCount ( )
virtual

Returns 1 if single threaded, 2 if multithreaded.

Returns
size_t

Reimplemented from RobotRaconteur::ThreadPool.

◆ Post()

RR_OVIRTUAL void RobotRaconteur::IOContextThreadPool::Post ( boost::function< void()> function)
virtual

Post a function to be executed by the thread pool in a worker thread and return immediately.

Parameters
functionThe function to execute

Reimplemented from RobotRaconteur::ThreadPool.

◆ SetThreadPoolCount()

RR_OVIRTUAL void RobotRaconteur::IOContextThreadPool::SetThreadPoolCount ( size_t count)
virtual

Invalid for IOContextThreadPool, throws InvalidOperationException.

The IOContextThreadPool does not control the number of threads

Parameters
count

Reimplemented from RobotRaconteur::ThreadPool.

◆ TryPost()

RR_OVIRTUAL bool RobotRaconteur::IOContextThreadPool::TryPost ( boost::function< void()> function)
virtual

Try posting a function to be executed by the thread pool in a worker thread and return immediately.

Parameters
functionThe function to execute
Returns
true The function was posted to the thread pool
false An error ocurred and the function was not posted

Reimplemented from RobotRaconteur::ThreadPool.


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