Internal use. More...
#include <callback_queue_manager.h>
Classes | |
struct | QueueInfo |
struct | ThreadInfo |
Public Member Functions | |
void | addQueue (const CallbackQueuePtr &queue, bool threaded) |
void | callbackAdded (const CallbackQueuePtr &queue) |
CallbackQueueManager (uint32_t num_worker_threads=0) | |
Constructor. | |
uint32_t | getNumWorkerThreads () |
void | removeQueue (const CallbackQueuePtr &queue) |
void | stop () |
~CallbackQueueManager () | |
Private Types | |
typedef boost::unordered_map < CallbackQueue *, QueueInfoPtr > | M_Queue |
typedef boost::shared_ptr < QueueInfo > | QueueInfoPtr |
typedef std::vector < CallbackQueuePtr > | V_Queue |
typedef boost::scoped_array < ThreadInfo > | V_ThreadInfo |
Private Member Functions | |
ThreadInfo * | getSmallestQueue () |
void | managerThread () |
void | workerThread (ThreadInfo *) |
Private Attributes | |
uint32_t | num_worker_threads_ |
M_Queue | queues_ |
boost::mutex | queues_mutex_ |
bool | running_ |
boost::thread_group | tg_ |
V_ThreadInfo | thread_info_ |
V_Queue | waiting_ |
boost::condition_variable | waiting_cond_ |
boost::mutex | waiting_mutex_ |
Internal use.
Manages a set of callback queues, potentially calling callbacks from them concurrently in different threads. Essentially a task manager specialized for callback queues.
Uses 1 manager thread + N worker threads. The manager thread gives work to the worker threads by finding the thread with the fewest pending tasks and appending to that list. This does mean that a single long-running callback can potentially block other callbacks from being executed. Some kind of work-stealing could mitigate this, and is a good direction for future work.
Definition at line 63 of file callback_queue_manager.h.
typedef boost::unordered_map<CallbackQueue*, QueueInfoPtr> nodelet::detail::CallbackQueueManager::M_Queue [private] |
Definition at line 109 of file callback_queue_manager.h.
typedef boost::shared_ptr<QueueInfo> nodelet::detail::CallbackQueueManager::QueueInfoPtr [private] |
Definition at line 107 of file callback_queue_manager.h.
typedef std::vector<CallbackQueuePtr> nodelet::detail::CallbackQueueManager::V_Queue [private] |
Definition at line 114 of file callback_queue_manager.h.
typedef boost::scoped_array<ThreadInfo> nodelet::detail::CallbackQueueManager::V_ThreadInfo [private] |
Definition at line 157 of file callback_queue_manager.h.
nodelet::detail::CallbackQueueManager::CallbackQueueManager | ( | uint32_t | num_worker_threads = 0 | ) |
Constructor.
By default, uses the number of hardware threads available on the current system.
Definition at line 46 of file callback_queue_manager.cpp.
Definition at line 63 of file callback_queue_manager.cpp.
void nodelet::detail::CallbackQueueManager::addQueue | ( | const CallbackQueuePtr & | queue, |
bool | threaded | ||
) |
Definition at line 110 of file callback_queue_manager.cpp.
void nodelet::detail::CallbackQueueManager::callbackAdded | ( | const CallbackQueuePtr & | queue | ) |
Definition at line 129 of file callback_queue_manager.cpp.
Definition at line 105 of file callback_queue_manager.cpp.
CallbackQueueManager::ThreadInfo * nodelet::detail::CallbackQueueManager::getSmallestQueue | ( | ) | [private] |
Definition at line 139 of file callback_queue_manager.cpp.
void nodelet::detail::CallbackQueueManager::managerThread | ( | ) | [private] |
Definition at line 163 of file callback_queue_manager.cpp.
void nodelet::detail::CallbackQueueManager::removeQueue | ( | const CallbackQueuePtr & | queue | ) |
Definition at line 121 of file callback_queue_manager.cpp.
Definition at line 87 of file callback_queue_manager.cpp.
void nodelet::detail::CallbackQueueManager::workerThread | ( | ThreadInfo * | info | ) | [private] |
Definition at line 244 of file callback_queue_manager.cpp.
uint32_t nodelet::detail::CallbackQueueManager::num_worker_threads_ [private] |
Definition at line 161 of file callback_queue_manager.h.
Definition at line 110 of file callback_queue_manager.h.
boost::mutex nodelet::detail::CallbackQueueManager::queues_mutex_ [private] |
Definition at line 111 of file callback_queue_manager.h.
bool nodelet::detail::CallbackQueueManager::running_ [private] |
Definition at line 160 of file callback_queue_manager.h.
boost::thread_group nodelet::detail::CallbackQueueManager::tg_ [private] |
Definition at line 118 of file callback_queue_manager.h.
Definition at line 158 of file callback_queue_manager.h.
Definition at line 115 of file callback_queue_manager.h.
boost::condition_variable nodelet::detail::CallbackQueueManager::waiting_cond_ [private] |
Definition at line 117 of file callback_queue_manager.h.
boost::mutex nodelet::detail::CallbackQueueManager::waiting_mutex_ [private] |
Definition at line 116 of file callback_queue_manager.h.