message_queue.hpp 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2005-2012. Distributed under the Boost
  4. // Software License, Version 1.0. (See accompanying file
  5. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // See http://www.boost.org/libs/interprocess for documentation.
  8. //
  9. //////////////////////////////////////////////////////////////////////////////
  10. #ifndef BOOST_INTERPROCESS_MESSAGE_QUEUE_HPP
  11. #define BOOST_INTERPROCESS_MESSAGE_QUEUE_HPP
  12. #ifndef BOOST_CONFIG_HPP
  13. # include <boost/config.hpp>
  14. #endif
  15. #
  16. #if defined(BOOST_HAS_PRAGMA_ONCE)
  17. # pragma once
  18. #endif
  19. #include <boost/interprocess/detail/config_begin.hpp>
  20. #include <boost/interprocess/detail/workaround.hpp>
  21. #include <boost/interprocess/shared_memory_object.hpp>
  22. #include <boost/interprocess/detail/managed_open_or_create_impl.hpp>
  23. #include <boost/interprocess/sync/interprocess_condition.hpp>
  24. #include <boost/interprocess/sync/interprocess_mutex.hpp>
  25. #include <boost/interprocess/sync/scoped_lock.hpp>
  26. #include <boost/interprocess/detail/utilities.hpp>
  27. #include <boost/interprocess/offset_ptr.hpp>
  28. #include <boost/interprocess/creation_tags.hpp>
  29. #include <boost/interprocess/exceptions.hpp>
  30. #include <boost/interprocess/permissions.hpp>
  31. #include <boost/core/no_exceptions_support.hpp>
  32. #include <boost/interprocess/detail/type_traits.hpp>
  33. #include <boost/intrusive/pointer_traits.hpp>
  34. #include <boost/move/detail/type_traits.hpp> //make_unsigned, alignment_of
  35. #include <boost/intrusive/pointer_traits.hpp>
  36. #include <boost/assert.hpp>
  37. #include <algorithm> //std::lower_bound
  38. #include <cstddef> //std::size_t
  39. #include <cstring> //memcpy
  40. //!\file
  41. //!Describes an inter-process message queue. This class allows sending
  42. //!messages between processes and allows blocking, non-blocking and timed
  43. //!sending and receiving.
  44. namespace boost{ namespace interprocess{
  45. namespace ipcdetail
  46. {
  47. template<class VoidPointer>
  48. class msg_queue_initialization_func_t;
  49. }
  50. //!A class that allows sending messages
  51. //!between processes.
  52. template<class VoidPointer>
  53. class message_queue_t
  54. {
  55. #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
  56. //Blocking modes
  57. enum block_t { blocking, timed, non_blocking };
  58. message_queue_t();
  59. #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
  60. public:
  61. typedef VoidPointer void_pointer;
  62. typedef typename boost::intrusive::
  63. pointer_traits<void_pointer>::template
  64. rebind_pointer<char>::type char_ptr;
  65. typedef typename boost::intrusive::pointer_traits<char_ptr>::difference_type difference_type;
  66. typedef typename boost::container::dtl::make_unsigned<difference_type>::type size_type;
  67. //!Creates a process shared message queue with name "name". For this message queue,
  68. //!the maximum number of messages will be "max_num_msg" and the maximum message size
  69. //!will be "max_msg_size". Throws on error and if the queue was previously created.
  70. message_queue_t(create_only_t create_only,
  71. const char *name,
  72. size_type max_num_msg,
  73. size_type max_msg_size,
  74. const permissions &perm = permissions());
  75. //!Opens or creates a process shared message queue with name "name".
  76. //!If the queue is created, the maximum number of messages will be "max_num_msg"
  77. //!and the maximum message size will be "max_msg_size". If queue was previously
  78. //!created the queue will be opened and "max_num_msg" and "max_msg_size" parameters
  79. //!are ignored. Throws on error.
  80. message_queue_t(open_or_create_t open_or_create,
  81. const char *name,
  82. size_type max_num_msg,
  83. size_type max_msg_size,
  84. const permissions &perm = permissions());
  85. //!Opens a previously created process shared message queue with name "name".
  86. //!If the queue was not previously created or there are no free resources,
  87. //!throws an error.
  88. message_queue_t(open_only_t open_only, const char *name);
  89. #if defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) || defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
  90. //!Creates a process shared message queue with name "name". For this message queue,
  91. //!the maximum number of messages will be "max_num_msg" and the maximum message size
  92. //!will be "max_msg_size". Throws on error and if the queue was previously created.
  93. //!
  94. //!Note: This function is only available on operating systems with
  95. //! native wchar_t APIs (e.g. Windows).
  96. message_queue_t(create_only_t create_only,
  97. const wchar_t *name,
  98. size_type max_num_msg,
  99. size_type max_msg_size,
  100. const permissions &perm = permissions());
  101. //!Opens or creates a process shared message queue with name "name".
  102. //!If the queue is created, the maximum number of messages will be "max_num_msg"
  103. //!and the maximum message size will be "max_msg_size". If queue was previously
  104. //!created the queue will be opened and "max_num_msg" and "max_msg_size" parameters
  105. //!are ignored. Throws on error.
  106. //!
  107. //!Note: This function is only available on operating systems with
  108. //! native wchar_t APIs (e.g. Windows).
  109. message_queue_t(open_or_create_t open_or_create,
  110. const wchar_t *name,
  111. size_type max_num_msg,
  112. size_type max_msg_size,
  113. const permissions &perm = permissions());
  114. //!Opens a previously created process shared message queue with name "name".
  115. //!If the queue was not previously created or there are no free resources,
  116. //!throws an error.
  117. //!
  118. //!Note: This function is only available on operating systems with
  119. //! native wchar_t APIs (e.g. Windows).
  120. message_queue_t(open_only_t open_only, const wchar_t *name);
  121. #endif //defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) || defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
  122. //!Destroys *this and indicates that the calling process is finished using
  123. //!the resource. All opened message queues are still
  124. //!valid after destruction. The destructor function will deallocate
  125. //!any system resources allocated by the system for use by this process for
  126. //!this resource. The resource can still be opened again calling
  127. //!the open constructor overload. To erase the message queue from the system
  128. //!use remove().
  129. ~message_queue_t();
  130. //!Sends a message stored in buffer "buffer" with size "buffer_size" in the
  131. //!message queue with priority "priority". If the message queue is full
  132. //!the sender is blocked. Throws interprocess_error on error.
  133. void send (const void *buffer, size_type buffer_size,
  134. unsigned int priority);
  135. //!Sends a message stored in buffer "buffer" with size "buffer_size" through the
  136. //!message queue with priority "priority". If the message queue is full
  137. //!the sender is not blocked and returns false, otherwise returns true.
  138. //!Throws interprocess_error on error.
  139. bool try_send (const void *buffer, size_type buffer_size,
  140. unsigned int priority);
  141. //!Sends a message stored in buffer "buffer" with size "buffer_size" in the
  142. //!message queue with priority "priority". If the message queue is full
  143. //!the sender retries until time "abs_time" is reached. Returns true if
  144. //!the message has been successfully sent. Returns false if timeout is reached.
  145. //!Throws interprocess_error on error.
  146. bool timed_send (const void *buffer, size_type buffer_size,
  147. unsigned int priority, const boost::posix_time::ptime& abs_time);
  148. //!Receives a message from the message queue. The message is stored in buffer
  149. //!"buffer", which has size "buffer_size". The received message has size
  150. //!"recvd_size" and priority "priority". If the message queue is empty
  151. //!the receiver is blocked. Throws interprocess_error on error.
  152. void receive (void *buffer, size_type buffer_size,
  153. size_type &recvd_size,unsigned int &priority);
  154. //!Receives a message from the message queue. The message is stored in buffer
  155. //!"buffer", which has size "buffer_size". The received message has size
  156. //!"recvd_size" and priority "priority". If the message queue is empty
  157. //!the receiver is not blocked and returns false, otherwise returns true.
  158. //!Throws interprocess_error on error.
  159. bool try_receive (void *buffer, size_type buffer_size,
  160. size_type &recvd_size,unsigned int &priority);
  161. //!Receives a message from the message queue. The message is stored in buffer
  162. //!"buffer", which has size "buffer_size". The received message has size
  163. //!"recvd_size" and priority "priority". If the message queue is empty
  164. //!the receiver retries until time "abs_time" is reached. Returns true if
  165. //!the message has been successfully sent. Returns false if timeout is reached.
  166. //!Throws interprocess_error on error.
  167. bool timed_receive (void *buffer, size_type buffer_size,
  168. size_type &recvd_size,unsigned int &priority,
  169. const boost::posix_time::ptime &abs_time);
  170. //!Returns the maximum number of messages allowed by the queue. The message
  171. //!queue must be opened or created previously. Otherwise, returns 0.
  172. //!Never throws
  173. size_type get_max_msg() const;
  174. //!Returns the maximum size of message allowed by the queue. The message
  175. //!queue must be opened or created previously. Otherwise, returns 0.
  176. //!Never throws
  177. size_type get_max_msg_size() const;
  178. //!Returns the number of messages currently stored.
  179. //!Never throws
  180. size_type get_num_msg() const;
  181. //!Removes the message queue from the system.
  182. //!Returns false on error. Never throws
  183. static bool remove(const char *name);
  184. #if defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) || defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
  185. //!Removes the message queue from the system.
  186. //!Returns false on error. Never throws
  187. //!
  188. //!Note: This function is only available on operating systems with
  189. //! native wchar_t APIs (e.g. Windows).
  190. static bool remove(const wchar_t *name);
  191. #endif
  192. #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
  193. private:
  194. typedef boost::posix_time::ptime ptime;
  195. friend class ipcdetail::msg_queue_initialization_func_t<VoidPointer>;
  196. bool do_receive(block_t block,
  197. void *buffer, size_type buffer_size,
  198. size_type &recvd_size, unsigned int &priority,
  199. const ptime &abs_time);
  200. bool do_send(block_t block,
  201. const void *buffer, size_type buffer_size,
  202. unsigned int priority, const ptime &abs_time);
  203. //!Returns the needed memory size for the shared message queue.
  204. //!Never throws
  205. static size_type get_mem_size(size_type max_msg_size, size_type max_num_msg);
  206. typedef ipcdetail::managed_open_or_create_impl<shared_memory_object, 0, true, false> open_create_impl_t;
  207. open_create_impl_t m_shmem;
  208. #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
  209. };
  210. #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
  211. namespace ipcdetail {
  212. //!This header is the prefix of each message in the queue
  213. template<class VoidPointer>
  214. class msg_hdr_t
  215. {
  216. typedef VoidPointer void_pointer;
  217. typedef typename boost::intrusive::
  218. pointer_traits<void_pointer>::template
  219. rebind_pointer<char>::type char_ptr;
  220. typedef typename boost::intrusive::pointer_traits<char_ptr>::difference_type difference_type;
  221. typedef typename boost::container::dtl::make_unsigned<difference_type>::type size_type;
  222. public:
  223. size_type len; // Message length
  224. unsigned int priority;// Message priority
  225. //!Returns the data buffer associated with this this message
  226. void * data(){ return this+1; } //
  227. };
  228. //!This functor is the predicate to order stored messages by priority
  229. template<class VoidPointer>
  230. class priority_functor
  231. {
  232. typedef typename boost::intrusive::
  233. pointer_traits<VoidPointer>::template
  234. rebind_pointer<msg_hdr_t<VoidPointer> >::type msg_hdr_ptr_t;
  235. public:
  236. bool operator()(const msg_hdr_ptr_t &msg1,
  237. const msg_hdr_ptr_t &msg2) const
  238. { return msg1->priority < msg2->priority; }
  239. };
  240. //!This header is placed in the beginning of the shared memory and contains
  241. //!the data to control the queue. This class initializes the shared memory
  242. //!in the following way: in ascending memory address with proper alignment
  243. //!fillings:
  244. //!
  245. //!-> mq_hdr_t:
  246. //! Main control block that controls the rest of the elements
  247. //!
  248. //!-> offset_ptr<msg_hdr_t> index [max_num_msg]
  249. //! An array of pointers with size "max_num_msg" called index. Each pointer
  250. //! points to a preallocated message. Elements of this array are
  251. //! reordered in runtime in the following way:
  252. //!
  253. //! IF BOOST_INTERPROCESS_MSG_QUEUE_CIRCULAR_INDEX is defined:
  254. //!
  255. //! When the current number of messages is "cur_num_msg", the array
  256. //! is treated like a circular buffer. Starting from position "cur_first_msg"
  257. //! "cur_num_msg" in a circular way, pointers point to inserted messages and the rest
  258. //! point to free messages. Those "cur_num_msg" pointers are
  259. //! ordered by the priority of the pointed message and by insertion order
  260. //! if two messages have the same priority. So the next message to be
  261. //! used in a "receive" is pointed by index [(cur_first_msg + cur_num_msg-1)%max_num_msg]
  262. //! and the first free message ready to be used in a "send" operation is
  263. //! [cur_first_msg] if circular buffer is extended from front,
  264. //! [(cur_first_msg + cur_num_msg)%max_num_msg] otherwise.
  265. //!
  266. //! This transforms the index in a circular buffer with an embedded free
  267. //! message queue.
  268. //!
  269. //! ELSE (BOOST_INTERPROCESS_MSG_QUEUE_CIRCULAR_INDEX is NOT defined):
  270. //!
  271. //! When the current number of messages is "cur_num_msg", the first
  272. //! "cur_num_msg" pointers point to inserted messages and the rest
  273. //! point to free messages. The first "cur_num_msg" pointers are
  274. //! ordered by the priority of the pointed message and by insertion order
  275. //! if two messages have the same priority. So the next message to be
  276. //! used in a "receive" is pointed by index [cur_num_msg-1] and the first free
  277. //! message ready to be used in a "send" operation is index [cur_num_msg].
  278. //!
  279. //! This transforms the index in a fixed size priority queue with an embedded free
  280. //! message queue.
  281. //!
  282. //!-> struct message_t
  283. //! {
  284. //! msg_hdr_t header;
  285. //! char[max_msg_size] data;
  286. //! } messages [max_num_msg];
  287. //!
  288. //! An array of buffers of preallocated messages, each one prefixed with the
  289. //! msg_hdr_t structure. Each of this message is pointed by one pointer of
  290. //! the index structure.
  291. template<class VoidPointer>
  292. class mq_hdr_t
  293. : public ipcdetail::priority_functor<VoidPointer>
  294. {
  295. typedef VoidPointer void_pointer;
  296. typedef msg_hdr_t<void_pointer> msg_header;
  297. typedef typename boost::intrusive::
  298. pointer_traits<void_pointer>::template
  299. rebind_pointer<msg_header>::type msg_hdr_ptr_t;
  300. typedef typename boost::intrusive::pointer_traits
  301. <msg_hdr_ptr_t>::difference_type difference_type;
  302. typedef typename boost::container::
  303. dtl::make_unsigned<difference_type>::type size_type;
  304. typedef typename boost::intrusive::
  305. pointer_traits<void_pointer>::template
  306. rebind_pointer<msg_hdr_ptr_t>::type msg_hdr_ptr_ptr_t;
  307. typedef ipcdetail::managed_open_or_create_impl<shared_memory_object, 0, true, false> open_create_impl_t;
  308. public:
  309. //!Constructor. This object must be constructed in the beginning of the
  310. //!shared memory of the size returned by the function "get_mem_size".
  311. //!This constructor initializes the needed resources and creates
  312. //!the internal structures like the priority index. This can throw.
  313. mq_hdr_t(size_type max_num_msg, size_type max_msg_size)
  314. : m_max_num_msg(max_num_msg),
  315. m_max_msg_size(max_msg_size),
  316. m_cur_num_msg(0)
  317. #if defined(BOOST_INTERPROCESS_MSG_QUEUE_CIRCULAR_INDEX)
  318. ,m_cur_first_msg(0u)
  319. ,m_blocked_senders(0u)
  320. ,m_blocked_receivers(0u)
  321. #endif
  322. { this->initialize_memory(); }
  323. //!Returns true if the message queue is full
  324. bool is_full() const
  325. { return m_cur_num_msg == m_max_num_msg; }
  326. //!Returns true if the message queue is empty
  327. bool is_empty() const
  328. { return !m_cur_num_msg; }
  329. //!Frees the top priority message and saves it in the free message list
  330. void free_top_msg()
  331. { --m_cur_num_msg; }
  332. #if defined(BOOST_INTERPROCESS_MSG_QUEUE_CIRCULAR_INDEX)
  333. typedef msg_hdr_ptr_t *iterator;
  334. size_type end_pos() const
  335. {
  336. const size_type space_until_bufend = m_max_num_msg - m_cur_first_msg;
  337. return space_until_bufend > m_cur_num_msg
  338. ? m_cur_first_msg + m_cur_num_msg : m_cur_num_msg - space_until_bufend;
  339. }
  340. //!Returns the inserted message with top priority
  341. msg_header &top_msg()
  342. {
  343. size_type pos = this->end_pos();
  344. return *mp_index[pos ? --pos : m_max_num_msg - 1];
  345. }
  346. //!Returns the inserted message with bottom priority
  347. msg_header &bottom_msg()
  348. { return *mp_index[m_cur_first_msg]; }
  349. iterator inserted_ptr_begin() const
  350. { return &mp_index[m_cur_first_msg]; }
  351. iterator inserted_ptr_end() const
  352. { return &mp_index[this->end_pos()]; }
  353. iterator lower_bound(const msg_hdr_ptr_t & value, priority_functor<VoidPointer> func)
  354. {
  355. iterator begin(this->inserted_ptr_begin()), end(this->inserted_ptr_end());
  356. if(end < begin){
  357. iterator idx_end = &mp_index[m_max_num_msg];
  358. iterator ret = std::lower_bound(begin, idx_end, value, func);
  359. if(idx_end == ret){
  360. iterator idx_beg = &mp_index[0];
  361. ret = std::lower_bound(idx_beg, end, value, func);
  362. //sanity check, these cases should not call lower_bound (optimized out)
  363. BOOST_ASSERT(ret != end);
  364. BOOST_ASSERT(ret != begin);
  365. return ret;
  366. }
  367. else{
  368. return ret;
  369. }
  370. }
  371. else{
  372. return std::lower_bound(begin, end, value, func);
  373. }
  374. }
  375. msg_header & insert_at(iterator where)
  376. {
  377. iterator it_inserted_ptr_end = this->inserted_ptr_end();
  378. iterator it_inserted_ptr_beg = this->inserted_ptr_begin();
  379. if(where == it_inserted_ptr_beg){
  380. //unsigned integer guarantees underflow
  381. m_cur_first_msg = m_cur_first_msg ? m_cur_first_msg : m_max_num_msg;
  382. --m_cur_first_msg;
  383. ++m_cur_num_msg;
  384. return *mp_index[m_cur_first_msg];
  385. }
  386. else if(where == it_inserted_ptr_end){
  387. ++m_cur_num_msg;
  388. return **it_inserted_ptr_end;
  389. }
  390. else{
  391. size_type pos = where - &mp_index[0];
  392. size_type circ_pos = pos >= m_cur_first_msg ? pos - m_cur_first_msg : pos + (m_max_num_msg - m_cur_first_msg);
  393. //Check if it's more efficient to move back or move front
  394. if(circ_pos < m_cur_num_msg/2){
  395. //The queue can't be full so m_cur_num_msg == 0 or m_cur_num_msg <= pos
  396. //indicates two step insertion
  397. if(!pos){
  398. pos = m_max_num_msg;
  399. where = &mp_index[m_max_num_msg-1];
  400. }
  401. else{
  402. --where;
  403. }
  404. const bool unique_segment = m_cur_first_msg && m_cur_first_msg <= pos;
  405. const size_type first_segment_beg = unique_segment ? m_cur_first_msg : 1u;
  406. const size_type first_segment_end = pos;
  407. const size_type second_segment_beg = unique_segment || !m_cur_first_msg ? m_max_num_msg : m_cur_first_msg;
  408. const size_type second_segment_end = m_max_num_msg;
  409. const msg_hdr_ptr_t backup = *(&mp_index[0] + (unique_segment ? first_segment_beg : second_segment_beg) - 1);
  410. //First segment
  411. if(!unique_segment){
  412. std::copy( &mp_index[0] + second_segment_beg
  413. , &mp_index[0] + second_segment_end
  414. , &mp_index[0] + second_segment_beg - 1);
  415. mp_index[m_max_num_msg-1] = mp_index[0];
  416. }
  417. std::copy( &mp_index[0] + first_segment_beg
  418. , &mp_index[0] + first_segment_end
  419. , &mp_index[0] + first_segment_beg - 1);
  420. *where = backup;
  421. m_cur_first_msg = m_cur_first_msg ? m_cur_first_msg : m_max_num_msg;
  422. --m_cur_first_msg;
  423. ++m_cur_num_msg;
  424. return **where;
  425. }
  426. else{
  427. //The queue can't be full so end_pos < m_cur_first_msg
  428. //indicates two step insertion
  429. const size_type pos_end = this->end_pos();
  430. const bool unique_segment = pos < pos_end;
  431. const size_type first_segment_beg = pos;
  432. const size_type first_segment_end = unique_segment ? pos_end : m_max_num_msg-1;
  433. const size_type second_segment_beg = 0u;
  434. const size_type second_segment_end = unique_segment ? 0u : pos_end;
  435. const msg_hdr_ptr_t backup = *it_inserted_ptr_end;
  436. //First segment
  437. if(!unique_segment){
  438. std::copy_backward( &mp_index[0] + second_segment_beg
  439. , &mp_index[0] + second_segment_end
  440. , &mp_index[0] + second_segment_end + 1);
  441. mp_index[0] = mp_index[m_max_num_msg-1];
  442. }
  443. std::copy_backward( &mp_index[0] + first_segment_beg
  444. , &mp_index[0] + first_segment_end
  445. , &mp_index[0] + first_segment_end + 1);
  446. *where = backup;
  447. ++m_cur_num_msg;
  448. return **where;
  449. }
  450. }
  451. }
  452. #else //BOOST_INTERPROCESS_MSG_QUEUE_CIRCULAR_INDEX
  453. typedef msg_hdr_ptr_t *iterator;
  454. //!Returns the inserted message with top priority
  455. msg_header &top_msg()
  456. { return *mp_index[m_cur_num_msg-1]; }
  457. //!Returns the inserted message with bottom priority
  458. msg_header &bottom_msg()
  459. { return *mp_index[0]; }
  460. iterator inserted_ptr_begin() const
  461. { return &mp_index[0]; }
  462. iterator inserted_ptr_end() const
  463. { return &mp_index[m_cur_num_msg]; }
  464. iterator lower_bound(const msg_hdr_ptr_t & value, priority_functor<VoidPointer> func)
  465. { return std::lower_bound(this->inserted_ptr_begin(), this->inserted_ptr_end(), value, func); }
  466. msg_header & insert_at(iterator pos)
  467. {
  468. const msg_hdr_ptr_t backup = *inserted_ptr_end();
  469. std::copy_backward(pos, inserted_ptr_end(), inserted_ptr_end()+1);
  470. *pos = backup;
  471. ++m_cur_num_msg;
  472. return **pos;
  473. }
  474. #endif //BOOST_INTERPROCESS_MSG_QUEUE_CIRCULAR_INDEX
  475. //!Inserts the first free message in the priority queue
  476. msg_header & queue_free_msg(unsigned int priority)
  477. {
  478. //Get priority queue's range
  479. iterator it (inserted_ptr_begin()), it_end(inserted_ptr_end());
  480. //Optimize for non-priority usage
  481. if(m_cur_num_msg && priority > this->bottom_msg().priority){
  482. //Check for higher priority than all stored messages
  483. if(priority > this->top_msg().priority){
  484. it = it_end;
  485. }
  486. else{
  487. //Since we don't now which free message we will pick
  488. //build a dummy header for searches
  489. msg_header dummy_hdr;
  490. dummy_hdr.priority = priority;
  491. //Get free msg
  492. msg_hdr_ptr_t dummy_ptr(&dummy_hdr);
  493. //Check where the free message should be placed
  494. it = this->lower_bound(dummy_ptr, static_cast<priority_functor<VoidPointer>&>(*this));
  495. }
  496. }
  497. //Insert the free message in the correct position
  498. return this->insert_at(it);
  499. }
  500. //!Returns the number of bytes needed to construct a message queue with
  501. //!"max_num_size" maximum number of messages and "max_msg_size" maximum
  502. //!message size. Never throws.
  503. static size_type get_mem_size
  504. (size_type max_msg_size, size_type max_num_msg)
  505. {
  506. const size_type
  507. msg_hdr_align = ::boost::container::dtl::alignment_of<msg_header>::value,
  508. index_align = ::boost::container::dtl::alignment_of<msg_hdr_ptr_t>::value,
  509. r_hdr_size = ipcdetail::ct_rounded_size<sizeof(mq_hdr_t), index_align>::value,
  510. r_index_size = ipcdetail::get_rounded_size<size_type>(max_num_msg*sizeof(msg_hdr_ptr_t), msg_hdr_align),
  511. r_max_msg_size = ipcdetail::get_rounded_size<size_type>(max_msg_size, msg_hdr_align) + sizeof(msg_header);
  512. return r_hdr_size + r_index_size + (max_num_msg*r_max_msg_size) +
  513. open_create_impl_t::ManagedOpenOrCreateUserOffset;
  514. }
  515. //!Initializes the memory structures to preallocate messages and constructs the
  516. //!message index. Never throws.
  517. void initialize_memory()
  518. {
  519. const size_type
  520. msg_hdr_align = ::boost::container::dtl::alignment_of<msg_header>::value,
  521. index_align = ::boost::container::dtl::alignment_of<msg_hdr_ptr_t>::value,
  522. r_hdr_size = ipcdetail::ct_rounded_size<sizeof(mq_hdr_t), index_align>::value,
  523. r_index_size = ipcdetail::get_rounded_size<size_type>(m_max_num_msg*sizeof(msg_hdr_ptr_t), msg_hdr_align),
  524. r_max_msg_size = ipcdetail::get_rounded_size<size_type>(m_max_msg_size, msg_hdr_align) + sizeof(msg_header);
  525. //Pointer to the index
  526. msg_hdr_ptr_t *index = reinterpret_cast<msg_hdr_ptr_t*>
  527. (reinterpret_cast<char*>(this)+r_hdr_size);
  528. //Pointer to the first message header
  529. msg_header *msg_hdr = reinterpret_cast<msg_header*>
  530. (reinterpret_cast<char*>(this)+r_hdr_size+r_index_size);
  531. //Initialize the pointer to the index
  532. mp_index = index;
  533. //Initialize the index so each slot points to a preallocated message
  534. for(size_type i = 0; i < m_max_num_msg; ++i){
  535. index[i] = msg_hdr;
  536. msg_hdr = reinterpret_cast<msg_header*>
  537. (reinterpret_cast<char*>(msg_hdr)+r_max_msg_size);
  538. }
  539. }
  540. public:
  541. //Pointer to the index
  542. msg_hdr_ptr_ptr_t mp_index;
  543. //Maximum number of messages of the queue
  544. const size_type m_max_num_msg;
  545. //Maximum size of messages of the queue
  546. const size_type m_max_msg_size;
  547. //Current number of messages
  548. size_type m_cur_num_msg;
  549. //Mutex to protect data structures
  550. interprocess_mutex m_mutex;
  551. //Condition block receivers when there are no messages
  552. interprocess_condition m_cond_recv;
  553. //Condition block senders when the queue is full
  554. interprocess_condition m_cond_send;
  555. #if defined(BOOST_INTERPROCESS_MSG_QUEUE_CIRCULAR_INDEX)
  556. //Current start offset in the circular index
  557. size_type m_cur_first_msg;
  558. size_type m_blocked_senders;
  559. size_type m_blocked_receivers;
  560. #endif
  561. };
  562. //!This is the atomic functor to be executed when creating or opening
  563. //!shared memory. Never throws
  564. template<class VoidPointer>
  565. class msg_queue_initialization_func_t
  566. {
  567. public:
  568. typedef typename boost::intrusive::
  569. pointer_traits<VoidPointer>::template
  570. rebind_pointer<char>::type char_ptr;
  571. typedef typename boost::intrusive::pointer_traits<char_ptr>::
  572. difference_type difference_type;
  573. typedef typename boost::container::dtl::
  574. make_unsigned<difference_type>::type size_type;
  575. msg_queue_initialization_func_t(size_type maxmsg = 0,
  576. size_type maxmsgsize = 0)
  577. : m_maxmsg (maxmsg), m_maxmsgsize(maxmsgsize) {}
  578. bool operator()(void *address, size_type, bool created)
  579. {
  580. char *mptr;
  581. if(created){
  582. mptr = reinterpret_cast<char*>(address);
  583. //Construct the message queue header at the beginning
  584. BOOST_TRY{
  585. new (mptr) mq_hdr_t<VoidPointer>(m_maxmsg, m_maxmsgsize);
  586. }
  587. BOOST_CATCH(...){
  588. return false;
  589. }
  590. BOOST_CATCH_END
  591. }
  592. return true;
  593. }
  594. std::size_t get_min_size() const
  595. {
  596. return mq_hdr_t<VoidPointer>::get_mem_size(m_maxmsgsize, m_maxmsg)
  597. - message_queue_t<VoidPointer>::open_create_impl_t::ManagedOpenOrCreateUserOffset;
  598. }
  599. const size_type m_maxmsg;
  600. const size_type m_maxmsgsize;
  601. };
  602. } //namespace ipcdetail {
  603. template<class VoidPointer>
  604. inline message_queue_t<VoidPointer>::~message_queue_t()
  605. {}
  606. template<class VoidPointer>
  607. inline typename message_queue_t<VoidPointer>::size_type message_queue_t<VoidPointer>::get_mem_size
  608. (size_type max_msg_size, size_type max_num_msg)
  609. { return ipcdetail::mq_hdr_t<VoidPointer>::get_mem_size(max_msg_size, max_num_msg); }
  610. template<class VoidPointer>
  611. inline message_queue_t<VoidPointer>::message_queue_t(create_only_t,
  612. const char *name,
  613. size_type max_num_msg,
  614. size_type max_msg_size,
  615. const permissions &perm)
  616. //Create shared memory and execute functor atomically
  617. : m_shmem(create_only,
  618. name,
  619. get_mem_size(max_msg_size, max_num_msg),
  620. read_write,
  621. static_cast<void*>(0),
  622. //Prepare initialization functor
  623. ipcdetail::msg_queue_initialization_func_t<VoidPointer> (max_num_msg, max_msg_size),
  624. perm)
  625. {}
  626. template<class VoidPointer>
  627. inline message_queue_t<VoidPointer>::message_queue_t(open_or_create_t,
  628. const char *name,
  629. size_type max_num_msg,
  630. size_type max_msg_size,
  631. const permissions &perm)
  632. //Create shared memory and execute functor atomically
  633. : m_shmem(open_or_create,
  634. name,
  635. get_mem_size(max_msg_size, max_num_msg),
  636. read_write,
  637. static_cast<void*>(0),
  638. //Prepare initialization functor
  639. ipcdetail::msg_queue_initialization_func_t<VoidPointer> (max_num_msg, max_msg_size),
  640. perm)
  641. {}
  642. template<class VoidPointer>
  643. inline message_queue_t<VoidPointer>::message_queue_t(open_only_t, const char *name)
  644. //Create shared memory and execute functor atomically
  645. : m_shmem(open_only,
  646. name,
  647. read_write,
  648. static_cast<void*>(0),
  649. //Prepare initialization functor
  650. ipcdetail::msg_queue_initialization_func_t<VoidPointer> ())
  651. {}
  652. #if defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) || defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
  653. template<class VoidPointer>
  654. inline message_queue_t<VoidPointer>::message_queue_t(create_only_t,
  655. const wchar_t *name,
  656. size_type max_num_msg,
  657. size_type max_msg_size,
  658. const permissions &perm)
  659. //Create shared memory and execute functor atomically
  660. : m_shmem(create_only,
  661. name,
  662. get_mem_size(max_msg_size, max_num_msg),
  663. read_write,
  664. static_cast<void*>(0),
  665. //Prepare initialization functor
  666. ipcdetail::msg_queue_initialization_func_t<VoidPointer> (max_num_msg, max_msg_size),
  667. perm)
  668. {}
  669. template<class VoidPointer>
  670. inline message_queue_t<VoidPointer>::message_queue_t(open_or_create_t,
  671. const wchar_t *name,
  672. size_type max_num_msg,
  673. size_type max_msg_size,
  674. const permissions &perm)
  675. //Create shared memory and execute functor atomically
  676. : m_shmem(open_or_create,
  677. name,
  678. get_mem_size(max_msg_size, max_num_msg),
  679. read_write,
  680. static_cast<void*>(0),
  681. //Prepare initialization functor
  682. ipcdetail::msg_queue_initialization_func_t<VoidPointer> (max_num_msg, max_msg_size),
  683. perm)
  684. {}
  685. template<class VoidPointer>
  686. inline message_queue_t<VoidPointer>::message_queue_t(open_only_t, const wchar_t *name)
  687. //Create shared memory and execute functor atomically
  688. : m_shmem(open_only,
  689. name,
  690. read_write,
  691. static_cast<void*>(0),
  692. //Prepare initialization functor
  693. ipcdetail::msg_queue_initialization_func_t<VoidPointer> ())
  694. {}
  695. #endif //defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) || defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
  696. template<class VoidPointer>
  697. inline void message_queue_t<VoidPointer>::send
  698. (const void *buffer, size_type buffer_size, unsigned int priority)
  699. { this->do_send(blocking, buffer, buffer_size, priority, ptime()); }
  700. template<class VoidPointer>
  701. inline bool message_queue_t<VoidPointer>::try_send
  702. (const void *buffer, size_type buffer_size, unsigned int priority)
  703. { return this->do_send(non_blocking, buffer, buffer_size, priority, ptime()); }
  704. template<class VoidPointer>
  705. inline bool message_queue_t<VoidPointer>::timed_send
  706. (const void *buffer, size_type buffer_size
  707. ,unsigned int priority, const boost::posix_time::ptime &abs_time)
  708. {
  709. if(abs_time.is_pos_infinity()){
  710. this->send(buffer, buffer_size, priority);
  711. return true;
  712. }
  713. return this->do_send(timed, buffer, buffer_size, priority, abs_time);
  714. }
  715. template<class VoidPointer>
  716. inline bool message_queue_t<VoidPointer>::do_send(block_t block,
  717. const void *buffer, size_type buffer_size,
  718. unsigned int priority, const boost::posix_time::ptime &abs_time)
  719. {
  720. ipcdetail::mq_hdr_t<VoidPointer> *p_hdr = static_cast<ipcdetail::mq_hdr_t<VoidPointer>*>(m_shmem.get_user_address());
  721. //Check if buffer is smaller than maximum allowed
  722. if (buffer_size > p_hdr->m_max_msg_size) {
  723. throw interprocess_exception(size_error);
  724. }
  725. #if defined(BOOST_INTERPROCESS_MSG_QUEUE_CIRCULAR_INDEX)
  726. bool notify_blocked_receivers = false;
  727. #endif
  728. //---------------------------------------------
  729. scoped_lock<interprocess_mutex> lock(p_hdr->m_mutex);
  730. //---------------------------------------------
  731. {
  732. //If the queue is full execute blocking logic
  733. if (p_hdr->is_full()) {
  734. BOOST_TRY{
  735. #ifdef BOOST_INTERPROCESS_MSG_QUEUE_CIRCULAR_INDEX
  736. ++p_hdr->m_blocked_senders;
  737. #endif
  738. switch(block){
  739. case non_blocking :
  740. #ifdef BOOST_INTERPROCESS_MSG_QUEUE_CIRCULAR_INDEX
  741. --p_hdr->m_blocked_senders;
  742. #endif
  743. return false;
  744. break;
  745. case blocking :
  746. do{
  747. p_hdr->m_cond_send.wait(lock);
  748. }
  749. while (p_hdr->is_full());
  750. break;
  751. case timed :
  752. do{
  753. if(!p_hdr->m_cond_send.timed_wait(lock, abs_time)){
  754. if(p_hdr->is_full()){
  755. #ifdef BOOST_INTERPROCESS_MSG_QUEUE_CIRCULAR_INDEX
  756. --p_hdr->m_blocked_senders;
  757. #endif
  758. return false;
  759. }
  760. break;
  761. }
  762. }
  763. while (p_hdr->is_full());
  764. break;
  765. default:
  766. break;
  767. }
  768. #ifdef BOOST_INTERPROCESS_MSG_QUEUE_CIRCULAR_INDEX
  769. --p_hdr->m_blocked_senders;
  770. #endif
  771. }
  772. BOOST_CATCH(...){
  773. #ifdef BOOST_INTERPROCESS_MSG_QUEUE_CIRCULAR_INDEX
  774. --p_hdr->m_blocked_senders;
  775. #endif
  776. BOOST_RETHROW;
  777. }
  778. BOOST_CATCH_END
  779. }
  780. #if defined(BOOST_INTERPROCESS_MSG_QUEUE_CIRCULAR_INDEX)
  781. notify_blocked_receivers = 0 != p_hdr->m_blocked_receivers;
  782. #endif
  783. //Insert the first free message in the priority queue
  784. ipcdetail::msg_hdr_t<VoidPointer> &free_msg_hdr = p_hdr->queue_free_msg(priority);
  785. //Sanity check, free msgs are always cleaned when received
  786. BOOST_ASSERT(free_msg_hdr.priority == 0);
  787. BOOST_ASSERT(free_msg_hdr.len == 0);
  788. //Copy control data to the free message
  789. free_msg_hdr.priority = priority;
  790. free_msg_hdr.len = buffer_size;
  791. //Copy user buffer to the message
  792. std::memcpy(free_msg_hdr.data(), buffer, buffer_size);
  793. } // Lock end
  794. //Notify outside lock to avoid contention. This might produce some
  795. //spurious wakeups, but it's usually far better than notifying inside.
  796. //If this message changes the queue empty state, notify it to receivers
  797. #if defined(BOOST_INTERPROCESS_MSG_QUEUE_CIRCULAR_INDEX)
  798. if (notify_blocked_receivers){
  799. p_hdr->m_cond_recv.notify_one();
  800. }
  801. #else
  802. p_hdr->m_cond_recv.notify_one();
  803. #endif
  804. return true;
  805. }
  806. template<class VoidPointer>
  807. inline void message_queue_t<VoidPointer>::receive(void *buffer, size_type buffer_size,
  808. size_type &recvd_size, unsigned int &priority)
  809. { this->do_receive(blocking, buffer, buffer_size, recvd_size, priority, ptime()); }
  810. template<class VoidPointer>
  811. inline bool
  812. message_queue_t<VoidPointer>::try_receive(void *buffer, size_type buffer_size,
  813. size_type &recvd_size, unsigned int &priority)
  814. { return this->do_receive(non_blocking, buffer, buffer_size, recvd_size, priority, ptime()); }
  815. template<class VoidPointer>
  816. inline bool
  817. message_queue_t<VoidPointer>::timed_receive(void *buffer, size_type buffer_size,
  818. size_type &recvd_size, unsigned int &priority,
  819. const boost::posix_time::ptime &abs_time)
  820. {
  821. if(abs_time.is_pos_infinity()){
  822. this->receive(buffer, buffer_size, recvd_size, priority);
  823. return true;
  824. }
  825. return this->do_receive(timed, buffer, buffer_size, recvd_size, priority, abs_time);
  826. }
  827. template<class VoidPointer>
  828. inline bool
  829. message_queue_t<VoidPointer>::do_receive(block_t block,
  830. void *buffer, size_type buffer_size,
  831. size_type &recvd_size, unsigned int &priority,
  832. const boost::posix_time::ptime &abs_time)
  833. {
  834. ipcdetail::mq_hdr_t<VoidPointer> *p_hdr = static_cast<ipcdetail::mq_hdr_t<VoidPointer>*>(m_shmem.get_user_address());
  835. //Check if buffer is big enough for any message
  836. if (buffer_size < p_hdr->m_max_msg_size) {
  837. throw interprocess_exception(size_error);
  838. }
  839. #if defined(BOOST_INTERPROCESS_MSG_QUEUE_CIRCULAR_INDEX)
  840. bool notify_blocked_senders = false;
  841. #endif
  842. //---------------------------------------------
  843. scoped_lock<interprocess_mutex> lock(p_hdr->m_mutex);
  844. //---------------------------------------------
  845. {
  846. //If there are no messages execute blocking logic
  847. if (p_hdr->is_empty()) {
  848. BOOST_TRY{
  849. #if defined(BOOST_INTERPROCESS_MSG_QUEUE_CIRCULAR_INDEX)
  850. ++p_hdr->m_blocked_receivers;
  851. #endif
  852. switch(block){
  853. case non_blocking :
  854. #if defined(BOOST_INTERPROCESS_MSG_QUEUE_CIRCULAR_INDEX)
  855. --p_hdr->m_blocked_receivers;
  856. #endif
  857. return false;
  858. break;
  859. case blocking :
  860. do{
  861. p_hdr->m_cond_recv.wait(lock);
  862. }
  863. while (p_hdr->is_empty());
  864. break;
  865. case timed :
  866. do{
  867. if(!p_hdr->m_cond_recv.timed_wait(lock, abs_time)){
  868. if(p_hdr->is_empty()){
  869. #if defined(BOOST_INTERPROCESS_MSG_QUEUE_CIRCULAR_INDEX)
  870. --p_hdr->m_blocked_receivers;
  871. #endif
  872. return false;
  873. }
  874. break;
  875. }
  876. }
  877. while (p_hdr->is_empty());
  878. break;
  879. //Paranoia check
  880. default:
  881. break;
  882. }
  883. #if defined(BOOST_INTERPROCESS_MSG_QUEUE_CIRCULAR_INDEX)
  884. --p_hdr->m_blocked_receivers;
  885. #endif
  886. }
  887. BOOST_CATCH(...){
  888. #if defined(BOOST_INTERPROCESS_MSG_QUEUE_CIRCULAR_INDEX)
  889. --p_hdr->m_blocked_receivers;
  890. #endif
  891. BOOST_RETHROW;
  892. }
  893. BOOST_CATCH_END
  894. }
  895. #ifdef BOOST_INTERPROCESS_MSG_QUEUE_CIRCULAR_INDEX
  896. notify_blocked_senders = 0 != p_hdr->m_blocked_senders;
  897. #endif
  898. //There is at least one message ready to pick, get the top one
  899. ipcdetail::msg_hdr_t<VoidPointer> &top_msg = p_hdr->top_msg();
  900. //Get data from the message
  901. recvd_size = top_msg.len;
  902. priority = top_msg.priority;
  903. //Some cleanup to ease debugging
  904. top_msg.len = 0;
  905. top_msg.priority = 0;
  906. //Copy data to receiver's bufers
  907. std::memcpy(buffer, top_msg.data(), recvd_size);
  908. //Free top message and put it in the free message list
  909. p_hdr->free_top_msg();
  910. } //Lock end
  911. //Notify outside lock to avoid contention. This might produce some
  912. //spurious wakeups, but it's usually far better than notifying inside.
  913. //If this reception changes the queue full state, notify senders
  914. #ifdef BOOST_INTERPROCESS_MSG_QUEUE_CIRCULAR_INDEX
  915. if (notify_blocked_senders){
  916. p_hdr->m_cond_send.notify_one();
  917. }
  918. #else
  919. p_hdr->m_cond_send.notify_one();
  920. #endif
  921. return true;
  922. }
  923. template<class VoidPointer>
  924. inline typename message_queue_t<VoidPointer>::size_type message_queue_t<VoidPointer>::get_max_msg() const
  925. {
  926. ipcdetail::mq_hdr_t<VoidPointer> *p_hdr = static_cast<ipcdetail::mq_hdr_t<VoidPointer>*>(m_shmem.get_user_address());
  927. return p_hdr ? p_hdr->m_max_num_msg : 0; }
  928. template<class VoidPointer>
  929. inline typename message_queue_t<VoidPointer>::size_type message_queue_t<VoidPointer>::get_max_msg_size() const
  930. {
  931. ipcdetail::mq_hdr_t<VoidPointer> *p_hdr = static_cast<ipcdetail::mq_hdr_t<VoidPointer>*>(m_shmem.get_user_address());
  932. return p_hdr ? p_hdr->m_max_msg_size : 0;
  933. }
  934. template<class VoidPointer>
  935. inline typename message_queue_t<VoidPointer>::size_type message_queue_t<VoidPointer>::get_num_msg() const
  936. {
  937. ipcdetail::mq_hdr_t<VoidPointer> *p_hdr = static_cast<ipcdetail::mq_hdr_t<VoidPointer>*>(m_shmem.get_user_address());
  938. if(p_hdr){
  939. //---------------------------------------------
  940. scoped_lock<interprocess_mutex> lock(p_hdr->m_mutex);
  941. //---------------------------------------------
  942. return p_hdr->m_cur_num_msg;
  943. }
  944. return 0;
  945. }
  946. template<class VoidPointer>
  947. inline bool message_queue_t<VoidPointer>::remove(const char *name)
  948. { return shared_memory_object::remove(name); }
  949. #if defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) || defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
  950. template<class VoidPointer>
  951. inline bool message_queue_t<VoidPointer>::remove(const wchar_t *name)
  952. { return shared_memory_object::remove(name); }
  953. #endif
  954. #else
  955. //!Typedef for a default message queue
  956. //!to be used between processes
  957. typedef message_queue_t<offset_ptr<void> > message_queue;
  958. #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
  959. }} //namespace boost{ namespace interprocess{
  960. #include <boost/interprocess/detail/config_end.hpp>
  961. #endif //#ifndef BOOST_INTERPROCESS_MESSAGE_QUEUE_HPP