diff options
Diffstat (limited to 'boost/interprocess/ipc/message_queue.hpp')
-rw-r--r-- | boost/interprocess/ipc/message_queue.hpp | 152 |
1 files changed, 76 insertions, 76 deletions
diff --git a/boost/interprocess/ipc/message_queue.hpp b/boost/interprocess/ipc/message_queue.hpp index d3846afb7c..67dd574f61 100644 --- a/boost/interprocess/ipc/message_queue.hpp +++ b/boost/interprocess/ipc/message_queue.hpp @@ -66,24 +66,24 @@ class message_queue_t //!the maximum number of messages will be "max_num_msg" and the maximum message size //!will be "max_msg_size". Throws on error and if the queue was previously created. message_queue_t(create_only_t create_only, - const char *name, - size_type max_num_msg, + const char *name, + size_type max_num_msg, size_type max_msg_size, const permissions &perm = permissions()); - //!Opens or creates a process shared message queue with name "name". - //!If the queue is created, the maximum number of messages will be "max_num_msg" - //!and the maximum message size will be "max_msg_size". If queue was previously + //!Opens or creates a process shared message queue with name "name". + //!If the queue is created, the maximum number of messages will be "max_num_msg" + //!and the maximum message size will be "max_msg_size". If queue was previously //!created the queue will be opened and "max_num_msg" and "max_msg_size" parameters //!are ignored. Throws on error. message_queue_t(open_or_create_t open_or_create, - const char *name, - size_type max_num_msg, + const char *name, + size_type max_num_msg, size_type max_msg_size, const permissions &perm = permissions()); - //!Opens a previously created process shared message queue with name "name". - //!If the queue was not previously created or there are no free resources, + //!Opens a previously created process shared message queue with name "name". + //!If the queue was not previously created or there are no free resources, //!throws an error. message_queue_t(open_only_t open_only, const char *name); @@ -95,65 +95,65 @@ class message_queue_t //!this resource. The resource can still be opened again calling //!the open constructor overload. To erase the message queue from the system //!use remove(). - ~message_queue_t(); + ~message_queue_t(); - //!Sends a message stored in buffer "buffer" with size "buffer_size" in the + //!Sends a message stored in buffer "buffer" with size "buffer_size" in the //!message queue with priority "priority". If the message queue is full //!the sender is blocked. Throws interprocess_error on error.*/ - void send (const void *buffer, size_type buffer_size, + void send (const void *buffer, size_type buffer_size, unsigned int priority); - //!Sends a message stored in buffer "buffer" with size "buffer_size" through the + //!Sends a message stored in buffer "buffer" with size "buffer_size" through the //!message queue with priority "priority". If the message queue is full //!the sender is not blocked and returns false, otherwise returns true. //!Throws interprocess_error on error. - bool try_send (const void *buffer, size_type buffer_size, + bool try_send (const void *buffer, size_type buffer_size, unsigned int priority); - //!Sends a message stored in buffer "buffer" with size "buffer_size" in the + //!Sends a message stored in buffer "buffer" with size "buffer_size" in the //!message queue with priority "priority". If the message queue is full //!the sender retries until time "abs_time" is reached. Returns true if //!the message has been successfully sent. Returns false if timeout is reached. //!Throws interprocess_error on error. - bool timed_send (const void *buffer, size_type buffer_size, + bool timed_send (const void *buffer, size_type buffer_size, unsigned int priority, const boost::posix_time::ptime& abs_time); - //!Receives a message from the message queue. The message is stored in buffer - //!"buffer", which has size "buffer_size". The received message has size + //!Receives a message from the message queue. The message is stored in buffer + //!"buffer", which has size "buffer_size". The received message has size //!"recvd_size" and priority "priority". If the message queue is empty //!the receiver is blocked. Throws interprocess_error on error. - void receive (void *buffer, size_type buffer_size, + void receive (void *buffer, size_type buffer_size, size_type &recvd_size,unsigned int &priority); - //!Receives a message from the message queue. The message is stored in buffer - //!"buffer", which has size "buffer_size". The received message has size + //!Receives a message from the message queue. The message is stored in buffer + //!"buffer", which has size "buffer_size". The received message has size //!"recvd_size" and priority "priority". If the message queue is empty //!the receiver is not blocked and returns false, otherwise returns true. //!Throws interprocess_error on error. - bool try_receive (void *buffer, size_type buffer_size, + bool try_receive (void *buffer, size_type buffer_size, size_type &recvd_size,unsigned int &priority); - //!Receives a message from the message queue. The message is stored in buffer - //!"buffer", which has size "buffer_size". The received message has size + //!Receives a message from the message queue. The message is stored in buffer + //!"buffer", which has size "buffer_size". The received message has size //!"recvd_size" and priority "priority". If the message queue is empty //!the receiver retries until time "abs_time" is reached. Returns true if //!the message has been successfully sent. Returns false if timeout is reached. //!Throws interprocess_error on error. - bool timed_receive (void *buffer, size_type buffer_size, + bool timed_receive (void *buffer, size_type buffer_size, size_type &recvd_size,unsigned int &priority, const boost::posix_time::ptime &abs_time); //!Returns the maximum number of messages allowed by the queue. The message - //!queue must be opened or created previously. Otherwise, returns 0. + //!queue must be opened or created previously. Otherwise, returns 0. //!Never throws size_type get_max_msg() const; //!Returns the maximum size of message allowed by the queue. The message - //!queue must be opened or created previously. Otherwise, returns 0. + //!queue must be opened or created previously. Otherwise, returns 0. //!Never throws size_type get_max_msg_size() const; - //!Returns the number of messages currently stored. + //!Returns the number of messages currently stored. //!Never throws size_type get_num_msg(); @@ -161,16 +161,16 @@ class message_queue_t //!Returns false on error. Never throws static bool remove(const char *name); - /// @cond + /// @cond private: typedef boost::posix_time::ptime ptime; bool do_receive(block_t block, - void *buffer, size_type buffer_size, + void *buffer, size_type buffer_size, size_type &recvd_size, unsigned int &priority, const ptime &abs_time); bool do_send(block_t block, - const void *buffer, size_type buffer_size, + const void *buffer, size_type buffer_size, unsigned int priority, const ptime &abs_time); //!Returns the needed memory size for the shared message queue. @@ -187,7 +187,7 @@ namespace ipcdetail { //!This header is the prefix of each message in the queue template<class VoidPointer> -class msg_hdr_t +class msg_hdr_t { typedef VoidPointer void_pointer; typedef typename boost::intrusive:: @@ -212,36 +212,36 @@ class priority_functor rebind_pointer<msg_hdr_t<VoidPointer> >::type msg_hdr_ptr_t; public: - bool operator()(const msg_hdr_ptr_t &msg1, + bool operator()(const msg_hdr_ptr_t &msg1, const msg_hdr_ptr_t &msg2) const { return msg1->priority < msg2->priority; } }; -//!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 +//!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: +//!-> 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. The elements of this array are +//! An array of pointers with size "max_num_msg" called index. Each pointer +//! points to a preallocated message. The elements of this array are //! reordered in runtime in the following way: //! -//! When the current number of messages is "cur_num_msg", the first +//! 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 +//! 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 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]; @@ -252,7 +252,7 @@ class priority_functor template<class VoidPointer> class mq_hdr_t : public ipcdetail::priority_functor<VoidPointer> -{ +{ typedef VoidPointer void_pointer; typedef msg_hdr_t<void_pointer> msg_header; typedef typename boost::intrusive:: @@ -266,12 +266,12 @@ class mq_hdr_t rebind_pointer<msg_hdr_ptr_t>::type msg_hdr_ptr_ptr_t; public: - //!Constructor. This object must be constructed in the beginning of the + //!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.*/ mq_hdr_t(size_type max_num_msg, size_type max_msg_size) - : m_max_num_msg(max_num_msg), + : m_max_num_msg(max_num_msg), m_max_msg_size(max_msg_size), m_cur_num_msg(0) { this->initialize_memory(); } @@ -298,7 +298,7 @@ class mq_hdr_t //!Inserts the first free message in the priority queue void queue_free_msg() - { + { //Get free msg msg_hdr_ptr_t free = mp_index[m_cur_num_msg]; //Get priority queue's range @@ -312,19 +312,19 @@ class mq_hdr_t ++m_cur_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 + //!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. static size_type get_mem_size (size_type max_msg_size, size_type max_num_msg) { - const size_type + const size_type msg_hdr_align = ::boost::alignment_of<msg_header>::value, index_align = ::boost::alignment_of<msg_hdr_ptr_t>::value, r_hdr_size = ipcdetail::ct_rounded_size<sizeof(mq_hdr_t), index_align>::value, r_index_size = ipcdetail::get_rounded_size(sizeof(msg_hdr_ptr_t)*max_num_msg, msg_hdr_align), r_max_msg_size = ipcdetail::get_rounded_size(max_msg_size, msg_hdr_align) + sizeof(msg_header); - return r_hdr_size + r_index_size + (max_num_msg*r_max_msg_size) + + return r_hdr_size + r_index_size + (max_num_msg*r_max_msg_size) + ipcdetail::managed_open_or_create_impl<shared_memory_object>::ManagedOpenOrCreateUserOffset; } @@ -332,7 +332,7 @@ class mq_hdr_t //!message index. Never throws. void initialize_memory() { - const size_type + const size_type msg_hdr_align = ::boost::alignment_of<msg_header>::value, index_align = ::boost::alignment_of<msg_hdr_ptr_t>::value, r_hdr_size = ipcdetail::ct_rounded_size<sizeof(mq_hdr_t), index_align>::value, @@ -345,7 +345,7 @@ class mq_hdr_t //Pointer to the first message header msg_header *msg_hdr = reinterpret_cast<msg_header*> - (reinterpret_cast<char*>(this)+r_hdr_size+r_index_size); + (reinterpret_cast<char*>(this)+r_hdr_size+r_index_size); //Initialize the pointer to the index mp_index = index; @@ -376,7 +376,7 @@ class mq_hdr_t }; -//!This is the atomic functor to be executed when creating or opening +//!This is the atomic functor to be executed when creating or opening //!shared memory. Never throws template<class VoidPointer> class initialization_func_t @@ -388,7 +388,7 @@ class initialization_func_t typedef typename boost::intrusive::pointer_traits<char_ptr>::difference_type difference_type; typedef typename boost::make_unsigned<difference_type>::type size_type; - initialization_func_t(size_type maxmsg = 0, + initialization_func_t(size_type maxmsg = 0, size_type maxmsgsize = 0) : m_maxmsg (maxmsg), m_maxmsgsize(maxmsgsize) {} @@ -403,7 +403,7 @@ class initialization_func_t new (mptr) mq_hdr_t<VoidPointer>(m_maxmsg, m_maxmsgsize); } BOOST_CATCH(...){ - return false; + return false; } BOOST_CATCH_END } @@ -426,13 +426,13 @@ inline typename message_queue_t<VoidPointer>::size_type message_queue_t<VoidPoin template<class VoidPointer> inline message_queue_t<VoidPointer>::message_queue_t(create_only_t create_only, - const char *name, - size_type max_num_msg, + const char *name, + size_type max_num_msg, size_type max_msg_size, const permissions &perm) //Create shared memory and execute functor atomically - : m_shmem(create_only, - name, + : m_shmem(create_only, + name, get_mem_size(max_msg_size, max_num_msg), read_write, static_cast<void*>(0), @@ -443,13 +443,13 @@ inline message_queue_t<VoidPointer>::message_queue_t(create_only_t create_only, template<class VoidPointer> inline message_queue_t<VoidPointer>::message_queue_t(open_or_create_t open_or_create, - const char *name, - size_type max_num_msg, + const char *name, + size_type max_num_msg, size_type max_msg_size, const permissions &perm) //Create shared memory and execute functor atomically - : m_shmem(open_or_create, - name, + : m_shmem(open_or_create, + name, get_mem_size(max_msg_size, max_num_msg), read_write, static_cast<void*>(0), @@ -462,7 +462,7 @@ template<class VoidPointer> inline message_queue_t<VoidPointer>::message_queue_t(open_only_t open_only, const char *name) //Create shared memory and execute functor atomically - : m_shmem(open_only, + : m_shmem(open_only, name, read_write, static_cast<void*>(0), @@ -494,7 +494,7 @@ inline bool message_queue_t<VoidPointer>::timed_send template<class VoidPointer> inline bool message_queue_t<VoidPointer>::do_send(block_t block, - const void *buffer, size_type buffer_size, + const void *buffer, size_type buffer_size, unsigned int priority, const boost::posix_time::ptime &abs_time) { ipcdetail::mq_hdr_t<VoidPointer> *p_hdr = static_cast<ipcdetail::mq_hdr_t<VoidPointer>*>(m_shmem.get_user_address()); @@ -536,7 +536,7 @@ inline bool message_queue_t<VoidPointer>::do_send(block_t block, break; } } - + //Get the first free message from free message queue ipcdetail::msg_hdr_t<VoidPointer> *free_msg = p_hdr->free_msg(); if (free_msg == 0) { @@ -553,7 +553,7 @@ inline bool message_queue_t<VoidPointer>::do_send(block_t block, // bool was_empty = p_hdr->is_empty(); //Insert the first free message in the priority queue p_hdr->queue_free_msg(); - + //If this message changes the queue empty state, notify it to receivers // if (was_empty){ p_hdr->m_cond_recv.notify_one(); @@ -564,19 +564,19 @@ inline bool message_queue_t<VoidPointer>::do_send(block_t block, } template<class VoidPointer> -inline void message_queue_t<VoidPointer>::receive(void *buffer, size_type buffer_size, +inline void message_queue_t<VoidPointer>::receive(void *buffer, size_type buffer_size, size_type &recvd_size, unsigned int &priority) { this->do_receive(blocking, buffer, buffer_size, recvd_size, priority, ptime()); } template<class VoidPointer> inline bool - message_queue_t<VoidPointer>::try_receive(void *buffer, size_type buffer_size, + message_queue_t<VoidPointer>::try_receive(void *buffer, size_type buffer_size, size_type &recvd_size, unsigned int &priority) { return this->do_receive(non_blocking, buffer, buffer_size, recvd_size, priority, ptime()); } template<class VoidPointer> inline bool - message_queue_t<VoidPointer>::timed_receive(void *buffer, size_type buffer_size, + message_queue_t<VoidPointer>::timed_receive(void *buffer, size_type buffer_size, size_type &recvd_size, unsigned int &priority, const boost::posix_time::ptime &abs_time) { @@ -590,7 +590,7 @@ inline bool template<class VoidPointer> inline bool message_queue_t<VoidPointer>::do_receive(block_t block, - void *buffer, size_type buffer_size, + void *buffer, size_type buffer_size, size_type &recvd_size, unsigned int &priority, const boost::posix_time::ptime &abs_time) { @@ -666,20 +666,20 @@ inline bool template<class VoidPointer> inline typename message_queue_t<VoidPointer>::size_type message_queue_t<VoidPointer>::get_max_msg() const -{ +{ ipcdetail::mq_hdr_t<VoidPointer> *p_hdr = static_cast<ipcdetail::mq_hdr_t<VoidPointer>*>(m_shmem.get_user_address()); return p_hdr ? p_hdr->m_max_num_msg : 0; } template<class VoidPointer> inline typename message_queue_t<VoidPointer>::size_type message_queue_t<VoidPointer>::get_max_msg_size() const -{ +{ ipcdetail::mq_hdr_t<VoidPointer> *p_hdr = static_cast<ipcdetail::mq_hdr_t<VoidPointer>*>(m_shmem.get_user_address()); - return p_hdr ? p_hdr->m_max_msg_size : 0; + return p_hdr ? p_hdr->m_max_msg_size : 0; } template<class VoidPointer> inline typename message_queue_t<VoidPointer>::size_type message_queue_t<VoidPointer>::get_num_msg() -{ +{ ipcdetail::mq_hdr_t<VoidPointer> *p_hdr = static_cast<ipcdetail::mq_hdr_t<VoidPointer>*>(m_shmem.get_user_address()); if(p_hdr){ //--------------------------------------------- @@ -688,7 +688,7 @@ inline typename message_queue_t<VoidPointer>::size_type message_queue_t<VoidPoin return p_hdr->m_cur_num_msg; } - return 0; + return 0; } template<class VoidPointer> |