segment_manager_helper.hpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  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_SEGMENT_MANAGER_BASE_HPP
  11. #define BOOST_INTERPROCESS_SEGMENT_MANAGER_BASE_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. // interprocess
  22. #include <boost/interprocess/exceptions.hpp>
  23. // interprocess/detail
  24. #include <boost/interprocess/detail/type_traits.hpp>
  25. #include <boost/interprocess/detail/utilities.hpp>
  26. // container/detail
  27. #include <boost/container/detail/type_traits.hpp> //alignment_of
  28. #include <boost/container/detail/minimal_char_traits_header.hpp>
  29. #include <boost/container/detail/placement_new.hpp>
  30. // intrusive
  31. #include <boost/intrusive/pointer_traits.hpp>
  32. // move/detail
  33. #include <boost/move/detail/type_traits.hpp> //make_unsigned
  34. #include <boost/move/detail/force_ptr.hpp>
  35. // other boost
  36. #include <boost/assert.hpp> //BOOST_ASSERT
  37. // std
  38. #include <cstddef> //std::size_t
  39. namespace boost{
  40. namespace interprocess{
  41. template<class MemoryManager>
  42. class segment_manager_base;
  43. //!An integer that describes the type of the
  44. //!instance constructed in memory
  45. enum instance_type { anonymous_type, named_type, unique_type, max_allocation_type };
  46. namespace ipcdetail{
  47. template<class MemoryAlgorithm>
  48. class mem_algo_deallocator
  49. {
  50. void * m_ptr;
  51. MemoryAlgorithm & m_algo;
  52. public:
  53. mem_algo_deallocator(void *ptr, MemoryAlgorithm &algo)
  54. : m_ptr(ptr), m_algo(algo)
  55. {}
  56. void release()
  57. { m_ptr = 0; }
  58. ~mem_algo_deallocator()
  59. { if(m_ptr) m_algo.deallocate(m_ptr); }
  60. };
  61. #if !defined(BOOST_INTERPROCESS_SEGMENT_MANAGER_ABI)
  62. #define BOOST_INTERPROCESS_SEGMENT_MANAGER_ABI 2
  63. #endif //#if !defined(BOOST_INTERPROCESS_SEGMENT_MANAGER_ABI)
  64. #if (BOOST_INTERPROCESS_SEGMENT_MANAGER_ABI == 1)
  65. template<class size_type>
  66. struct block_header
  67. {
  68. private:
  69. const size_type m_value_bytes;
  70. const unsigned short m_num_char;
  71. const unsigned char m_value_alignment;
  72. const unsigned char m_alloc_type_sizeof_char;
  73. public:
  74. typedef std::size_t name_len_t;
  75. block_header(size_type val_bytes
  76. ,size_type val_alignment
  77. ,unsigned char al_type
  78. ,std::size_t szof_char
  79. ,std::size_t num_char
  80. )
  81. : m_value_bytes(val_bytes)
  82. , m_num_char((unsigned short)num_char)
  83. , m_value_alignment((unsigned char)val_alignment)
  84. , m_alloc_type_sizeof_char( (unsigned char)((al_type << 5u) | ((unsigned char)szof_char & 0x1F)) )
  85. {};
  86. template<std::size_t>
  87. size_type total_anonymous_size() const
  88. {
  89. return this->value_offset() + m_value_bytes;
  90. }
  91. template<std::size_t, class>
  92. size_type total_named_size(std::size_t namelen) const
  93. {
  94. (void)namelen;
  95. BOOST_ASSERT(namelen == m_num_char);
  96. return name_offset() + (m_num_char+1u)*sizeof_char();
  97. }
  98. template<std::size_t, class, class Header>
  99. size_type total_named_size_with_header(std::size_t namelen) const
  100. {
  101. BOOST_ASSERT(namelen == m_num_char);
  102. return get_rounded_size
  103. ( size_type(sizeof(Header))
  104. , size_type(::boost::container::dtl::alignment_of<block_header<size_type> >::value))
  105. + this->template total_named_size<0, char>(namelen);
  106. }
  107. size_type value_bytes() const
  108. { return m_value_bytes; }
  109. unsigned char alloc_type() const
  110. { return (m_alloc_type_sizeof_char >> 5u)&(unsigned char)0x7; }
  111. unsigned char sizeof_char() const
  112. { return m_alloc_type_sizeof_char & (unsigned char)0x1F; }
  113. template<class CharType>
  114. CharType *name() const
  115. {
  116. return const_cast<CharType*>(move_detail::force_ptr<const CharType*>
  117. (reinterpret_cast<const char*>(this) + name_offset()));
  118. }
  119. unsigned short name_length() const
  120. { return m_num_char; }
  121. void *value() const
  122. {
  123. return const_cast<char*>((reinterpret_cast<const char*>(this) + this->value_offset()));
  124. }
  125. template<class T>
  126. static block_header *block_header_from_value(T *value)
  127. {
  128. // BOOST_ASSERT(is_ptr_aligned(value, algn));
  129. const std::size_t algn = ::boost::container::dtl::alignment_of<T>::value;
  130. block_header* hdr =
  131. const_cast<block_header*>
  132. (move_detail::force_ptr<const block_header*>(reinterpret_cast<const char*>(value) -
  133. get_rounded_size(sizeof(block_header), algn)));
  134. //Some sanity checks
  135. BOOST_ASSERT(hdr->m_value_alignment == algn);
  136. BOOST_ASSERT(hdr->m_value_bytes % sizeof(T) == 0);
  137. return hdr;
  138. }
  139. template<class Header>
  140. static block_header *from_first_header(Header *header)
  141. {
  142. block_header * hdr =
  143. move_detail::force_ptr<block_header*>(reinterpret_cast<char*>(header) +
  144. get_rounded_size( size_type(sizeof(Header))
  145. , size_type(::boost::container::dtl::alignment_of<block_header >::value)));
  146. //Some sanity checks
  147. return hdr;
  148. }
  149. template<class Header>
  150. static const block_header *from_first_header(const Header *header)
  151. { return from_first_header(const_cast<Header*>(header)); }
  152. template<class Header>
  153. static Header *to_first_header(block_header *bheader)
  154. {
  155. Header * hdr =
  156. move_detail::force_ptr<Header*>(reinterpret_cast<char*>(bheader) -
  157. get_rounded_size( size_type(sizeof(Header))
  158. , size_type(::boost::container::dtl::alignment_of<block_header >::value)));
  159. //Some sanity checks
  160. return hdr;
  161. }
  162. template<std::size_t>
  163. static size_type front_space_without_header()
  164. { return 0u; }
  165. template<std::size_t, class>
  166. static size_type front_space_with_header()
  167. { return 0u; }
  168. void store_name_length(std::size_t)
  169. {}
  170. private:
  171. size_type value_offset() const
  172. {
  173. return get_rounded_size(size_type(sizeof(block_header)), size_type(m_value_alignment));
  174. }
  175. size_type name_offset() const
  176. {
  177. return this->value_offset() + get_rounded_size(size_type(m_value_bytes), size_type(sizeof_char()));
  178. }
  179. };
  180. #elif (BOOST_INTERPROCESS_SEGMENT_MANAGER_ABI == 2)
  181. template <class BlockHeader, class Header>
  182. struct sm_between_headers
  183. {
  184. BOOST_STATIC_CONSTEXPR std::size_t value
  185. = sizeof(Header)
  186. + ct_rounded_size< sizeof(BlockHeader), boost::move_detail::alignment_of<Header>::value>::value
  187. - sizeof(BlockHeader);
  188. };
  189. template <std::size_t TypeAlignment, class BlockHeader, class Header>
  190. struct sg_offsets_with_header
  191. {
  192. private:
  193. BOOST_STATIC_CONSTEXPR std::size_t between_headers = sm_between_headers<BlockHeader, Header>::value;
  194. BOOST_STATIC_CONSTEXPR std::size_t both_headers = between_headers + sizeof(BlockHeader);
  195. BOOST_STATIC_CONSTEXPR std::size_t total_prefix = ct_rounded_size<both_headers, TypeAlignment>::value;
  196. public:
  197. BOOST_STATIC_CONSTEXPR std::size_t block_header_prefix = total_prefix - sizeof(BlockHeader);
  198. BOOST_STATIC_CONSTEXPR std::size_t front_space = total_prefix - both_headers;
  199. BOOST_INTERPROCESS_STATIC_ASSERT((total_prefix % TypeAlignment) == 0);
  200. BOOST_INTERPROCESS_STATIC_ASSERT((front_space % boost::move_detail::alignment_of<Header>::value) == 0);
  201. BOOST_INTERPROCESS_STATIC_ASSERT((block_header_prefix % boost::move_detail::alignment_of<BlockHeader>::value) == 0);
  202. BOOST_INTERPROCESS_STATIC_ASSERT(total_prefix == (sizeof(BlockHeader) + sizeof(Header) + front_space + (between_headers - sizeof(Header))));
  203. };
  204. template <std::size_t TypeAlignment, class BlockHeader>
  205. struct sg_offsets_without_header
  206. {
  207. BOOST_STATIC_CONSTEXPR std::size_t total_prefix = ct_rounded_size<sizeof(BlockHeader), TypeAlignment>::value;
  208. public:
  209. BOOST_STATIC_CONSTEXPR std::size_t block_header_prefix = total_prefix - sizeof(BlockHeader);
  210. BOOST_STATIC_CONSTEXPR std::size_t front_space = block_header_prefix;
  211. };
  212. template<class size_type>
  213. struct block_header
  214. {
  215. private:
  216. const size_type m_alloc_type : 2;
  217. const size_type m_value_bytes : sizeof(size_type)*CHAR_BIT - 2u;
  218. public:
  219. typedef unsigned short name_len_t;
  220. block_header(size_type val_bytes
  221. ,size_type
  222. ,unsigned char al_type
  223. ,std::size_t
  224. ,std::size_t
  225. )
  226. : m_alloc_type(al_type & 3u)
  227. , m_value_bytes(val_bytes & (~size_type(0) >> 2u))
  228. {};
  229. template<std::size_t TypeAlignment>
  230. size_type total_anonymous_size() const
  231. {
  232. BOOST_CONSTEXPR_OR_CONST std::size_t block_header_prefix =
  233. sg_offsets_without_header<TypeAlignment, block_header>::block_header_prefix;
  234. return block_header_prefix + this->value_offset() + m_value_bytes;
  235. }
  236. template<std::size_t TypeAlignment, class CharType>
  237. size_type total_named_size(std::size_t namelen) const
  238. {
  239. BOOST_CONSTEXPR_OR_CONST std::size_t block_header_prefix =
  240. sg_offsets_without_header<TypeAlignment, block_header>::block_header_prefix;
  241. return block_header_prefix
  242. + name_offset< ::boost::move_detail::alignment_of<CharType>::value>()
  243. + (namelen + 1u) * sizeof(CharType);
  244. }
  245. template<std::size_t TypeAlignment, class CharType, class Header>
  246. size_type total_named_size_with_header(std::size_t namelen) const
  247. {
  248. typedef sg_offsets_with_header<TypeAlignment, block_header, Header> offsets_t;
  249. return offsets_t::block_header_prefix
  250. + name_offset< ::boost::move_detail::alignment_of<CharType>::value>()
  251. + (namelen + 1u) * sizeof(CharType);
  252. }
  253. size_type value_bytes() const
  254. { return m_value_bytes; }
  255. unsigned char alloc_type() const
  256. { return m_alloc_type; }
  257. template<class CharType>
  258. CharType *name() const
  259. {
  260. return const_cast<CharType*>(move_detail::force_ptr<const CharType*>
  261. (reinterpret_cast<const char*>(this) +
  262. this->template name_offset< ::boost::move_detail::alignment_of<CharType>::value>()));
  263. }
  264. name_len_t name_length() const
  265. {
  266. if(m_alloc_type == anonymous_type)
  267. return 0;
  268. return *(move_detail::force_ptr<const name_len_t*>
  269. (reinterpret_cast<const char*>(this) + this->name_length_offset()));
  270. }
  271. void *value() const
  272. { return const_cast<char*>((reinterpret_cast<const char*>(this) + this->value_offset())); }
  273. template<class T>
  274. static block_header *block_header_from_value(T *value)
  275. {
  276. BOOST_ASSERT(is_ptr_aligned(value, ::boost::container::dtl::alignment_of<T>::value));
  277. block_header* hdr =
  278. const_cast<block_header*>
  279. (move_detail::force_ptr<const block_header*>
  280. (reinterpret_cast<const char*>(value) - value_offset()));
  281. //Some sanity checks
  282. BOOST_ASSERT(hdr->m_value_bytes % sizeof(T) == 0);
  283. return hdr;
  284. }
  285. template<class Header>
  286. static block_header *from_first_header(Header *header)
  287. {
  288. BOOST_ASSERT(is_ptr_aligned(header));
  289. block_header * const hdr = move_detail::force_ptr<block_header*>(
  290. reinterpret_cast<char*>(header) + sm_between_headers<block_header, Header>::value);
  291. //Some sanity checks
  292. BOOST_ASSERT(is_ptr_aligned(hdr));
  293. return hdr;
  294. }
  295. template<class Header>
  296. static const block_header *from_first_header(const Header *header)
  297. { return from_first_header(const_cast<Header*>(header)); }
  298. template<class Header>
  299. static Header *to_first_header(block_header *bheader)
  300. {
  301. BOOST_ASSERT(is_ptr_aligned(bheader));
  302. Header * hdr = move_detail::force_ptr<Header*>(
  303. reinterpret_cast<char*>(bheader) - sm_between_headers<block_header, Header>::value);
  304. //Some sanity checks
  305. BOOST_ASSERT(is_ptr_aligned(hdr));
  306. return hdr;
  307. }
  308. template<std::size_t TypeAlignment, class Header>
  309. static size_type front_space_with_header()
  310. { return sg_offsets_with_header<TypeAlignment, block_header, Header>::front_space; }
  311. template<std::size_t TypeAlignment>
  312. static size_type front_space_without_header()
  313. { return sg_offsets_without_header<TypeAlignment, block_header>::front_space; }
  314. void store_name_length(name_len_t namelen)
  315. {
  316. ::new( reinterpret_cast<char*>(this) + this->name_length_offset()
  317. , boost_container_new_t()
  318. ) name_len_t(namelen);
  319. }
  320. private:
  321. static size_type value_offset()
  322. { return size_type(sizeof(block_header)); }
  323. template<std::size_t CharAlign>
  324. size_type name_offset() const
  325. { return get_rounded_size( size_type(this->name_length_offset()+sizeof(name_len_t))
  326. , size_type(CharAlign)); }
  327. size_type name_length_offset() const
  328. {
  329. return this->value_offset() +
  330. get_rounded_size( size_type(m_value_bytes)
  331. , size_type(::boost::move_detail::alignment_of<name_len_t>::value));
  332. }
  333. };
  334. #else //(BOOST_INTERPROCESS_SEGMENT_MANAGER_ABI == )
  335. #error "Incorrect BOOST_INTERPROCESS_SEGMENT_MANAGER_ABI value!"
  336. #endif
  337. template<class CharT>
  338. struct intrusive_compare_key
  339. {
  340. typedef CharT char_type;
  341. intrusive_compare_key(const CharT* str_, std::size_t len_)
  342. : mp_str(str_), m_len(len_)
  343. {}
  344. const CharT* str() const
  345. {
  346. return mp_str;
  347. }
  348. std::size_t len() const
  349. {
  350. return m_len;
  351. }
  352. const CharT* mp_str;
  353. std::size_t m_len;
  354. };
  355. //!This struct indicates an anonymous object creation
  356. //!allocation
  357. template<instance_type type>
  358. class instance_t
  359. {
  360. instance_t(){}
  361. };
  362. template<class T>
  363. struct char_if_void
  364. {
  365. typedef T type;
  366. };
  367. template<>
  368. struct char_if_void<void>
  369. {
  370. typedef char type;
  371. };
  372. typedef instance_t<anonymous_type> anonymous_instance_t;
  373. typedef instance_t<unique_type> unique_instance_t;
  374. template<class Hook, class CharType, class SizeType>
  375. struct intrusive_value_type_impl
  376. : public Hook
  377. {
  378. private:
  379. //Non-copyable
  380. intrusive_value_type_impl(const intrusive_value_type_impl &);
  381. intrusive_value_type_impl& operator=(const intrusive_value_type_impl &);
  382. public:
  383. typedef CharType char_type;
  384. typedef SizeType size_type;
  385. typedef block_header<size_type> block_header_t;
  386. intrusive_value_type_impl(){}
  387. CharType *name() const
  388. { return get_block_header()->template name<CharType>(); }
  389. unsigned short name_length() const
  390. { return get_block_header()->name_length(); }
  391. void *value() const
  392. { return get_block_header()->value(); }
  393. private:
  394. const block_header_t *get_block_header() const
  395. { return block_header_t::from_first_header(this); }
  396. };
  397. template<class CharType>
  398. class char_ptr_holder
  399. {
  400. public:
  401. char_ptr_holder(const CharType *name)
  402. : m_name(name)
  403. {}
  404. char_ptr_holder(const anonymous_instance_t *)
  405. : m_name(static_cast<CharType*>(0))
  406. {}
  407. char_ptr_holder(const unique_instance_t *)
  408. : m_name(reinterpret_cast<CharType*>(-1))
  409. {}
  410. operator const CharType *()
  411. { return m_name; }
  412. const CharType *get() const
  413. { return m_name; }
  414. bool is_unique() const
  415. { return m_name == reinterpret_cast<CharType*>(-1); }
  416. bool is_anonymous() const
  417. { return m_name == static_cast<CharType*>(0); }
  418. private:
  419. const CharType *m_name;
  420. };
  421. //!The key of the the named allocation information index. Stores an offset pointer
  422. //!to a null terminated string and the length of the string to speed up sorting
  423. template<class CharT, class VoidPointer>
  424. struct index_key
  425. {
  426. typedef typename boost::intrusive::
  427. pointer_traits<VoidPointer>::template
  428. rebind_pointer<const CharT>::type const_char_ptr_t;
  429. typedef CharT char_type;
  430. typedef typename boost::intrusive::pointer_traits<const_char_ptr_t>::difference_type difference_type;
  431. typedef typename boost::move_detail::make_unsigned<difference_type>::type size_type;
  432. private:
  433. //Offset pointer to the object's name
  434. const_char_ptr_t mp_str;
  435. //Length of the name buffer (null NOT included)
  436. size_type m_len;
  437. public:
  438. //!Constructor of the key
  439. index_key (const char_type *nm, size_type length)
  440. : mp_str(nm), m_len(length)
  441. {}
  442. //!Less than function for index ordering
  443. bool operator < (const index_key & right) const
  444. {
  445. return (m_len < right.m_len) ||
  446. (m_len == right.m_len &&
  447. std::char_traits<char_type>::compare
  448. (to_raw_pointer(mp_str),to_raw_pointer(right.mp_str), m_len) < 0);
  449. }
  450. //!Equal to function for index ordering
  451. bool operator == (const index_key & right) const
  452. {
  453. return m_len == right.m_len &&
  454. std::char_traits<char_type>::compare
  455. (to_raw_pointer(mp_str), to_raw_pointer(right.mp_str), m_len) == 0;
  456. }
  457. void name(const CharT *nm)
  458. { mp_str = nm; }
  459. void name_length(size_type len)
  460. { m_len = len; }
  461. const CharT *name() const
  462. { return to_raw_pointer(mp_str); }
  463. size_type name_length() const
  464. { return m_len; }
  465. };
  466. //!The index_data stores a pointer to a buffer and the element count needed
  467. //!to know how many destructors must be called when calling destroy
  468. template<class VoidPointer>
  469. struct index_data
  470. {
  471. typedef VoidPointer void_pointer;
  472. void_pointer m_ptr;
  473. explicit index_data(void *ptr) : m_ptr(ptr){}
  474. void *value() const
  475. { return static_cast<void*>(to_raw_pointer(m_ptr)); }
  476. };
  477. template<class MemoryAlgorithm>
  478. struct segment_manager_base_type
  479. { typedef segment_manager_base<MemoryAlgorithm> type; };
  480. template<class CharT, class MemoryAlgorithm>
  481. struct index_config
  482. {
  483. typedef typename MemoryAlgorithm::void_pointer void_pointer;
  484. typedef CharT char_type;
  485. typedef index_key<CharT, void_pointer> key_type;
  486. typedef index_data<void_pointer> mapped_type;
  487. typedef typename segment_manager_base_type
  488. <MemoryAlgorithm>::type segment_manager_base;
  489. template<class HeaderBase>
  490. struct intrusive_value_type
  491. {
  492. typedef intrusive_value_type_impl
  493. < HeaderBase
  494. , CharT
  495. , typename segment_manager_base::size_type
  496. > type;
  497. };
  498. typedef intrusive_compare_key<CharT> compare_key_type;
  499. };
  500. template<class Iterator, bool intrusive>
  501. class segment_manager_iterator_value_adaptor
  502. {
  503. typedef typename Iterator::value_type iterator_val_t;
  504. typedef typename iterator_val_t::char_type char_type;
  505. public:
  506. segment_manager_iterator_value_adaptor(const typename Iterator::value_type &val)
  507. : m_val(&val)
  508. {}
  509. const char_type *name() const
  510. { return m_val->name(); }
  511. unsigned short name_length() const
  512. { return m_val->name_length(); }
  513. const void *value() const
  514. { return m_val->value(); }
  515. const typename Iterator::value_type *m_val;
  516. };
  517. template<class Iterator>
  518. class segment_manager_iterator_value_adaptor<Iterator, false>
  519. {
  520. typedef typename Iterator::value_type iterator_val_t;
  521. typedef typename iterator_val_t::first_type first_type;
  522. typedef typename iterator_val_t::second_type second_type;
  523. typedef typename first_type::char_type char_type;
  524. typedef typename first_type::size_type size_type;
  525. public:
  526. segment_manager_iterator_value_adaptor(const typename Iterator::value_type &val)
  527. : m_val(&val)
  528. {}
  529. const char_type *name() const
  530. { return m_val->first.name(); }
  531. size_type name_length() const
  532. { return m_val->first.name_length(); }
  533. const void *value() const
  534. {
  535. return move_detail::force_ptr<block_header<size_type>*>
  536. (to_raw_pointer(m_val->second.m_ptr))->value();
  537. }
  538. const typename Iterator::value_type *m_val;
  539. };
  540. template<class Iterator, bool intrusive>
  541. struct segment_manager_iterator_transform
  542. {
  543. typedef segment_manager_iterator_value_adaptor<Iterator, intrusive> result_type;
  544. template <class T> result_type operator()(const T &arg) const
  545. { return result_type(arg); }
  546. };
  547. template<class T>
  548. inline T* null_or_bad_alloc(bool dothrow)
  549. {
  550. if (dothrow)
  551. throw bad_alloc();
  552. return 0;
  553. }
  554. template<class T>
  555. inline T* null_or_already_exists(bool dothrow)
  556. {
  557. if (dothrow)
  558. throw interprocess_exception(already_exists_error);
  559. return 0;
  560. }
  561. } //namespace ipcdetail {
  562. //These pointers are the ones the user will use to
  563. //indicate previous allocation types
  564. static const ipcdetail::anonymous_instance_t * anonymous_instance = 0;
  565. static const ipcdetail::unique_instance_t * unique_instance = 0;
  566. namespace ipcdetail_really_deep_namespace {
  567. //Otherwise, gcc issues a warning of previously defined
  568. //anonymous_instance and unique_instance
  569. struct dummy
  570. {
  571. dummy()
  572. {
  573. (void)anonymous_instance;
  574. (void)unique_instance;
  575. }
  576. };
  577. } //detail_really_deep_namespace
  578. }} //namespace boost { namespace interprocess
  579. #include <boost/interprocess/detail/config_end.hpp>
  580. #endif //#ifndef BOOST_INTERPROCESS_SEGMENT_MANAGER_BASE_HPP