|
Robot Raconteur Core C++ Library
|
Thread pool for Robot Raconteur nodes. More...
#include <ThreadPool.h>
Public Member Functions | |
| ThreadPool (const boost::shared_ptr< RobotRaconteurNode > &node) | |
| Construct a new ThreadPool. | |
| virtual size_t | GetThreadPoolCount () |
| Get the number of threads in the thread pool. | |
| virtual void | SetThreadPoolCount (size_t count) |
| Set the desired number of threads in the thread pool. | |
| virtual void | Post (boost::function< void()> function) |
| Post a function to be executed by the thread pool in a worker thread and return immediately. | |
| virtual bool | TryPost (boost::function< void()> function) |
| Try posting a function to be executed by the thread pool in a worker thread and return immediately. | |
| virtual boost::asio::io_context & | get_io_context () |
| Get the boost::asio::io_context object. | |
Thread pool for Robot Raconteur nodes.
See threading for more information on threading.
Robot Raconteur uses a Boost.Asio IO Context with a thread pool to handle network and other events. ThreadPool implements a multi-threaded pool that by default starts 20 threads. These threads wait for events and are dispatched by IO Context.
ThreadPool is normally created by the node using ThreadPoolFactory. The factory is configured using RobotRaconteurNode::SetThreadPoolFactory(). The thread pool may optionally be configured using the RobotRaconteurNode::SetThreadPool() if the thread pool is created directly.
The boost::asio::io_context object can be accessed using the ThreadPool::get_io_context() function. This can be used to initialize Boost.Asio objects like boost::asio::ip::tcp::socket and boost::asio::deadline_timer.
The IOContextThreadPool subclass of ThreadPool can be used if an external thread pool is used by an application. This is particularly useful for environments where single threaded operation is required, such as a simulation environment.
| RobotRaconteur::ThreadPool::ThreadPool | ( | const boost::shared_ptr< RobotRaconteurNode > & | node | ) |
Construct a new ThreadPool.
Must use boost::make_shared<ThreadPool>()
Use of ThreadPoolFactory is recommended.
Set the thread pool using RobotRaconteurNode::SetThreadPool()
| node | The node that owns the thread pool |
|
virtual |
Get the boost::asio::io_context object.
Use the returned boost::asio::io_context reference to initialize Boost.Asio objects
Reimplemented in RobotRaconteur::IOContextThreadPool.
|
virtual |
Get the number of threads in the thread pool.
Reimplemented in RobotRaconteur::IOContextThreadPool.
|
virtual |
Post a function to be executed by the thread pool in a worker thread and return immediately.
| function | The function to execute |
Reimplemented in RobotRaconteur::IOContextThreadPool.
|
virtual |
Set the desired number of threads in the thread pool.
Setting less than two threads may have unpredictable results
| count | The desired number of threads |
Reimplemented in RobotRaconteur::IOContextThreadPool.
|
virtual |
Try posting a function to be executed by the thread pool in a worker thread and return immediately.
| function | The function to execute |
Reimplemented in RobotRaconteur::IOContextThreadPool.