Boost  v1.57.0
doxygen for www.boost.org
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
boost::interprocess::ipcdetail::mq_hdr_t< VoidPointer > Class Template Reference

This header is placed in the beginning of the shared memory and contains the data to control the queue. More...

#include <message_queue.hpp>

Inheritance diagram for boost::interprocess::ipcdetail::mq_hdr_t< VoidPointer >:
Collaboration diagram for boost::interprocess::ipcdetail::mq_hdr_t< VoidPointer >:

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_headertop_msg ()
 Returns the inserted message with top priority. More...
 
msg_headerbottom_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_headerinsert_at (iterator pos)
 
msg_headerqueue_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
 

Detailed Description

template<class VoidPointer>
class boost::interprocess::ipcdetail::mq_hdr_t< VoidPointer >

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.

Member Typedef Documentation

template<class VoidPointer>
typedef msg_hdr_ptr_t* boost::interprocess::ipcdetail::mq_hdr_t< VoidPointer >::iterator

Constructor & Destructor Documentation

template<class VoidPointer>
boost::interprocess::ipcdetail::mq_hdr_t< VoidPointer >::mq_hdr_t ( size_type  max_num_msg,
size_type  max_msg_size 
)
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().

Member Function Documentation

template<class VoidPointer>
msg_header& boost::interprocess::ipcdetail::mq_hdr_t< VoidPointer >::bottom_msg ( )
inline

Returns the inserted message with bottom priority.

Referenced by boost::interprocess::ipcdetail::mq_hdr_t< VoidPointer >::queue_free_msg().

template<class VoidPointer>
void boost::interprocess::ipcdetail::mq_hdr_t< VoidPointer >::free_top_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.

template<class VoidPointer>
static size_type boost::interprocess::ipcdetail::mq_hdr_t< VoidPointer >::get_mem_size ( size_type  max_msg_size,
size_type  max_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().

template<class VoidPointer>
void boost::interprocess::ipcdetail::mq_hdr_t< VoidPointer >::initialize_memory ( )
inline
template<class VoidPointer>
bool boost::interprocess::ipcdetail::mq_hdr_t< VoidPointer >::is_empty ( ) const
inline

Returns true if the message queue is empty.

References boost::interprocess::ipcdetail::mq_hdr_t< VoidPointer >::m_cur_num_msg.

template<class VoidPointer>
bool boost::interprocess::ipcdetail::mq_hdr_t< VoidPointer >::is_full ( ) const
inline
template<class VoidPointer>
bool boost::interprocess::ipcdetail::priority_functor< VoidPointer >::operator() ( const msg_hdr_ptr_t &  msg1,
const msg_hdr_ptr_t &  msg2 
) const
inlineinherited
template<class VoidPointer>
msg_header& boost::interprocess::ipcdetail::mq_hdr_t< VoidPointer >::top_msg ( )
inline

Member Data Documentation

template<class VoidPointer>
interprocess_condition boost::interprocess::ipcdetail::mq_hdr_t< VoidPointer >::m_cond_recv
template<class VoidPointer>
interprocess_condition boost::interprocess::ipcdetail::mq_hdr_t< VoidPointer >::m_cond_send
template<class VoidPointer>
msg_hdr_ptr_ptr_t boost::interprocess::ipcdetail::mq_hdr_t< VoidPointer >::mp_index

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