This header is placed in the beginning of the shared memory and contains the data to control the queue. More...
#include <message_queue.hpp>
Public Types | |
typedef msg_hdr_ptr_t * | iterator |
Public Member Functions | |
mq_hdr_t (size_type max_num_msg, size_type max_msg_size) | |
Constructor. More... | |
bool | is_full () const |
Returns true if the message queue is full. More... | |
bool | is_empty () const |
Returns true if the message queue is empty. More... | |
void | free_top_msg () |
Frees the top priority message and saves it in the free message list. More... | |
msg_header & | top_msg () |
Returns the inserted message with top priority. More... | |
msg_header & | bottom_msg () |
Returns the inserted message with bottom priority. More... | |
iterator | inserted_ptr_begin () const |
iterator | inserted_ptr_end () const |
iterator | lower_bound (const msg_hdr_ptr_t &value, priority_functor< VoidPointer > func) |
msg_header & | insert_at (iterator pos) |
msg_header & | queue_free_msg (unsigned int priority) |
Inserts the first free message in the priority queue. More... | |
void | initialize_memory () |
Initializes the memory structures to preallocate messages and constructs the message index. More... | |
bool | operator() (const msg_hdr_ptr_t &msg1, const msg_hdr_ptr_t &msg2) const |
Static Public Member Functions | |
static size_type | get_mem_size (size_type max_msg_size, size_type max_num_msg) |
Returns the number of bytes needed to construct a message queue with "max_num_size" maximum number of messages and "max_msg_size" maximum message size. More... | |
Public Attributes | |
msg_hdr_ptr_ptr_t | mp_index |
const size_type | m_max_num_msg |
const size_type | m_max_msg_size |
size_type | m_cur_num_msg |
interprocess_mutex | m_mutex |
interprocess_condition | m_cond_recv |
interprocess_condition | m_cond_send |
This header is placed in the beginning of the shared memory and contains the data to control the queue.
This class initializes the shared memory in the following way: in ascending memory address with proper alignment fillings:
-> mq_hdr_t: Main control block that controls the rest of the elements
-> offset_ptr<msg_hdr_t> index [max_num_msg] An array of pointers with size "max_num_msg" called index. Each pointer points to a preallocated message. Elements of this array are reordered in runtime in the following way:
IF BOOST_INTERPROCESS_MSG_QUEUE_CIRCULAR_INDEX is defined:
When the current number of messages is "cur_num_msg", the array is treated like a circular buffer. Starting from position "cur_first_msg" "cur_num_msg" in a circular way, pointers point to inserted messages and the rest point to free messages. Those "cur_num_msg" pointers are ordered by the priority of the pointed message and by insertion order if two messages have the same priority. So the next message to be used in a "receive" is pointed by index [(cur_first_msg + cur_num_msg-1)max_num_msg] and the first free message ready to be used in a "send" operation is [cur_first_msg] if circular buffer is extended from front, [(cur_first_msg + cur_num_msg)max_num_msg] otherwise.
This transforms the index in a circular buffer with an embedded free message queue.
ELSE (BOOST_INTERPROCESS_MSG_QUEUE_CIRCULAR_INDEX is NOT defined):
When the current number of messages is "cur_num_msg", the first "cur_num_msg" pointers point to inserted messages and the rest point to free messages. The first "cur_num_msg" pointers are ordered by the priority of the pointed message and by insertion order if two messages have the same priority. So the next message to be used in a "receive" is pointed by index [cur_num_msg-1] and the first free message ready to be used in a "send" operation is index [cur_num_msg].
This transforms the index in a fixed size priority queue with an embedded free message queue.
-> struct message_t { msg_hdr_t header; char[max_msg_size] data; } messages [max_num_msg];
An array of buffers of preallocated messages, each one prefixed with the msg_hdr_t structure. Each of this message is pointed by one pointer of the index structure.
typedef msg_hdr_ptr_t* boost::interprocess::ipcdetail::mq_hdr_t< VoidPointer >::iterator |
|
inline |
Constructor.
This object must be constructed in the beginning of the shared memory of the size returned by the function "get_mem_size". This constructor initializes the needed resources and creates the internal structures like the priority index. This can throw.
References boost::interprocess::ipcdetail::mq_hdr_t< VoidPointer >::initialize_memory().
|
inline |
Returns the inserted message with bottom priority.
Referenced by boost::interprocess::ipcdetail::mq_hdr_t< VoidPointer >::queue_free_msg().
|
inline |
Frees the top priority message and saves it in the free message list.
References boost::interprocess::ipcdetail::mq_hdr_t< VoidPointer >::m_cur_num_msg.
|
inlinestatic |
Returns the number of bytes needed to construct a message queue with "max_num_size" maximum number of messages and "max_msg_size" maximum message size.
Never throws.
References boost::program_options::value().
Referenced by boost::interprocess::ipcdetail::msg_queue_initialization_func_t< VoidPointer >::get_min_size().
|
inline |
Initializes the memory structures to preallocate messages and constructs the message index.
Never throws.
References boost::multiprecision::backends::i, boost::interprocess::ipcdetail::mq_hdr_t< VoidPointer >::m_max_msg_size, boost::interprocess::ipcdetail::mq_hdr_t< VoidPointer >::m_max_num_msg, and boost::program_options::value().
Referenced by boost::interprocess::ipcdetail::mq_hdr_t< VoidPointer >::mq_hdr_t().
|
inline |
|
inline |
|
inline |
References boost::interprocess::ipcdetail::mq_hdr_t< VoidPointer >::m_cur_num_msg.
Referenced by boost::interprocess::ipcdetail::mq_hdr_t< VoidPointer >::insert_at(), boost::interprocess::ipcdetail::mq_hdr_t< VoidPointer >::lower_bound(), and boost::interprocess::ipcdetail::mq_hdr_t< VoidPointer >::queue_free_msg().
|
inline |
Returns true if the message queue is empty.
References boost::interprocess::ipcdetail::mq_hdr_t< VoidPointer >::m_cur_num_msg.
|
inline |
Returns true if the message queue is full.
References boost::interprocess::ipcdetail::mq_hdr_t< VoidPointer >::m_cur_num_msg, and boost::interprocess::ipcdetail::mq_hdr_t< VoidPointer >::m_max_num_msg.
|
inline |
References boost::interprocess::ipcdetail::mq_hdr_t< VoidPointer >::inserted_ptr_begin(), boost::interprocess::ipcdetail::mq_hdr_t< VoidPointer >::inserted_ptr_end(), and boost::numeric::ublas::detail::lower_bound().
Referenced by boost::interprocess::ipcdetail::mq_hdr_t< VoidPointer >::queue_free_msg().
|
inlineinherited |
|
inline |
Inserts the first free message in the priority queue.
References boost::interprocess::ipcdetail::mq_hdr_t< VoidPointer >::bottom_msg(), boost::interprocess::ipcdetail::mq_hdr_t< VoidPointer >::insert_at(), boost::interprocess::ipcdetail::mq_hdr_t< VoidPointer >::inserted_ptr_begin(), boost::interprocess::ipcdetail::mq_hdr_t< VoidPointer >::inserted_ptr_end(), boost::it, boost::interprocess::ipcdetail::mq_hdr_t< VoidPointer >::lower_bound(), boost::interprocess::ipcdetail::mq_hdr_t< VoidPointer >::m_cur_num_msg, boost::interprocess::ipcdetail::msg_hdr_t< VoidPointer >::priority, and boost::interprocess::ipcdetail::mq_hdr_t< VoidPointer >::top_msg().
|
inline |
Returns the inserted message with top priority.
References boost::interprocess::ipcdetail::mq_hdr_t< VoidPointer >::m_cur_num_msg.
Referenced by boost::interprocess::ipcdetail::mq_hdr_t< VoidPointer >::queue_free_msg().
interprocess_condition boost::interprocess::ipcdetail::mq_hdr_t< VoidPointer >::m_cond_recv |
interprocess_condition boost::interprocess::ipcdetail::mq_hdr_t< VoidPointer >::m_cond_send |
size_type boost::interprocess::ipcdetail::mq_hdr_t< VoidPointer >::m_cur_num_msg |
Referenced by boost::interprocess::ipcdetail::mq_hdr_t< VoidPointer >::free_top_msg(), boost::interprocess::message_queue_t< VoidPointer >::get_num_msg(), boost::interprocess::ipcdetail::mq_hdr_t< VoidPointer >::insert_at(), boost::interprocess::ipcdetail::mq_hdr_t< VoidPointer >::inserted_ptr_end(), boost::interprocess::ipcdetail::mq_hdr_t< VoidPointer >::is_empty(), boost::interprocess::ipcdetail::mq_hdr_t< VoidPointer >::is_full(), boost::interprocess::ipcdetail::mq_hdr_t< VoidPointer >::queue_free_msg(), and boost::interprocess::ipcdetail::mq_hdr_t< VoidPointer >::top_msg().
const size_type boost::interprocess::ipcdetail::mq_hdr_t< VoidPointer >::m_max_msg_size |
const size_type boost::interprocess::ipcdetail::mq_hdr_t< VoidPointer >::m_max_num_msg |
interprocess_mutex boost::interprocess::ipcdetail::mq_hdr_t< VoidPointer >::m_mutex |
msg_hdr_ptr_ptr_t boost::interprocess::ipcdetail::mq_hdr_t< VoidPointer >::mp_index |