File indexing completed on 2025-12-16 09:53:23
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_INTERPROCESS_PRIVATE_NODE_ALLOCATOR_HPP
0012 #define BOOST_INTERPROCESS_PRIVATE_NODE_ALLOCATOR_HPP
0013
0014 #ifndef BOOST_CONFIG_HPP
0015 # include <boost/config.hpp>
0016 #endif
0017 #
0018 #if defined(BOOST_HAS_PRAGMA_ONCE)
0019 # pragma once
0020 #endif
0021
0022 #include <boost/interprocess/detail/config_begin.hpp>
0023 #include <boost/interprocess/detail/workaround.hpp>
0024
0025 #include <boost/intrusive/pointer_traits.hpp>
0026
0027 #include <boost/interprocess/interprocess_fwd.hpp>
0028 #include <boost/assert.hpp>
0029 #include <boost/container/detail/addressof.hpp>
0030 #include <boost/interprocess/allocators/detail/node_pool.hpp>
0031 #include <boost/interprocess/containers/version_type.hpp>
0032 #include <boost/container/detail/multiallocation_chain.hpp>
0033 #include <boost/interprocess/exceptions.hpp>
0034 #include <boost/interprocess/detail/utilities.hpp>
0035 #include <boost/interprocess/detail/workaround.hpp>
0036 #include <boost/move/adl_move_swap.hpp>
0037 #include <cstddef>
0038
0039
0040
0041
0042 namespace boost {
0043 namespace interprocess {
0044
0045 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0046
0047 namespace ipcdetail {
0048
0049 template < unsigned int Version
0050 , class T
0051 , class SegmentManager
0052 , std::size_t NodesPerBlock
0053 >
0054 class private_node_allocator_base
0055 : public node_pool_allocation_impl
0056 < private_node_allocator_base < Version, T, SegmentManager, NodesPerBlock>
0057 , Version
0058 , T
0059 , SegmentManager
0060 >
0061 {
0062 public:
0063
0064 typedef SegmentManager segment_manager;
0065 typedef typename SegmentManager::void_pointer void_pointer;
0066
0067 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0068 private:
0069 typedef private_node_allocator_base
0070 < Version, T, SegmentManager, NodesPerBlock> self_t;
0071 typedef ipcdetail::private_node_pool
0072 <SegmentManager
0073 , sizeof_value<T>::value
0074 , NodesPerBlock
0075 > node_pool_t;
0076
0077 BOOST_INTERPROCESS_STATIC_ASSERT((Version <=2));
0078
0079 #endif
0080
0081 public:
0082
0083 typedef typename boost::intrusive::
0084 pointer_traits<void_pointer>::template
0085 rebind_pointer<T>::type pointer;
0086 typedef typename boost::intrusive::
0087 pointer_traits<void_pointer>::template
0088 rebind_pointer<const T>::type const_pointer;
0089 typedef T value_type;
0090 typedef typename ipcdetail::add_reference
0091 <value_type>::type reference;
0092 typedef typename ipcdetail::add_reference
0093 <const value_type>::type const_reference;
0094 typedef typename segment_manager::size_type size_type;
0095 typedef typename segment_manager::difference_type difference_type;
0096 typedef boost::interprocess::version_type
0097 <private_node_allocator_base, Version> version;
0098 typedef boost::container::dtl::transform_multiallocation_chain
0099 <typename SegmentManager::multiallocation_chain, T>multiallocation_chain;
0100
0101
0102 template<class T2>
0103 struct rebind
0104 {
0105 typedef private_node_allocator_base
0106 <Version, T2, SegmentManager, NodesPerBlock> other;
0107 };
0108
0109 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0110 template <int dummy>
0111 struct node_pool
0112 {
0113 typedef ipcdetail::private_node_pool
0114 <SegmentManager
0115 , sizeof_value<T>::value
0116 , NodesPerBlock
0117 > type;
0118
0119 static type *get(void *p)
0120 { return static_cast<type*>(p); }
0121 };
0122
0123 private:
0124
0125 template<unsigned int Version2, class T2, class MemoryAlgorithm2, std::size_t N2>
0126 private_node_allocator_base& operator=
0127 (const private_node_allocator_base<Version2, T2, MemoryAlgorithm2, N2>&);
0128
0129
0130 private_node_allocator_base& operator=(const private_node_allocator_base&);
0131 #endif
0132
0133 public:
0134
0135 private_node_allocator_base(segment_manager *segment_mngr)
0136 : m_node_pool(segment_mngr)
0137 {}
0138
0139
0140 private_node_allocator_base(const private_node_allocator_base &other)
0141 : m_node_pool(other.get_segment_manager())
0142 {}
0143
0144
0145 template<class T2>
0146 private_node_allocator_base
0147 (const private_node_allocator_base
0148 <Version, T2, SegmentManager, NodesPerBlock> &other)
0149 : m_node_pool(other.get_segment_manager())
0150 {}
0151
0152
0153 ~private_node_allocator_base()
0154 {}
0155
0156
0157 segment_manager* get_segment_manager()const
0158 { return m_node_pool.get_segment_manager(); }
0159
0160
0161 node_pool_t* get_node_pool() const
0162 { return const_cast<node_pool_t*>(&m_node_pool); }
0163
0164
0165
0166 friend void swap(self_t &alloc1,self_t &alloc2)
0167 { boost::adl_move_swap(alloc1.m_node_pool, alloc2.m_node_pool); }
0168
0169 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0170 private:
0171 node_pool_t m_node_pool;
0172 #endif
0173 };
0174
0175
0176 template<unsigned int V, class T, class S, std::size_t NPC> inline
0177 bool operator==(const private_node_allocator_base<V, T, S, NPC> &alloc1,
0178 const private_node_allocator_base<V, T, S, NPC> &alloc2)
0179 { return &alloc1 == &alloc2; }
0180
0181
0182 template<unsigned int V, class T, class S, std::size_t NPC> inline
0183 bool operator!=(const private_node_allocator_base<V, T, S, NPC> &alloc1,
0184 const private_node_allocator_base<V, T, S, NPC> &alloc2)
0185 { return &alloc1 != &alloc2; }
0186
0187 template < class T
0188 , class SegmentManager
0189 , std::size_t NodesPerBlock = 64
0190 >
0191 class private_node_allocator_v1
0192 : public private_node_allocator_base
0193 < 1
0194 , T
0195 , SegmentManager
0196 , NodesPerBlock
0197 >
0198 {
0199 public:
0200 typedef ipcdetail::private_node_allocator_base
0201 < 1, T, SegmentManager, NodesPerBlock> base_t;
0202
0203 template<class T2>
0204 struct rebind
0205 {
0206 typedef private_node_allocator_v1<T2, SegmentManager, NodesPerBlock> other;
0207 };
0208
0209 private_node_allocator_v1(SegmentManager *segment_mngr)
0210 : base_t(segment_mngr)
0211 {}
0212
0213 template<class T2>
0214 private_node_allocator_v1
0215 (const private_node_allocator_v1<T2, SegmentManager, NodesPerBlock> &other)
0216 : base_t(other)
0217 {}
0218 };
0219
0220 }
0221
0222 #endif
0223
0224
0225
0226
0227
0228
0229
0230 template < class T
0231 , class SegmentManager
0232 , std::size_t NodesPerBlock
0233 >
0234 class private_node_allocator
0235 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0236 : public ipcdetail::private_node_allocator_base
0237 < 2
0238 , T
0239 , SegmentManager
0240 , NodesPerBlock
0241 >
0242 #endif
0243 {
0244
0245 #ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0246 typedef ipcdetail::private_node_allocator_base
0247 < 2, T, SegmentManager, NodesPerBlock> base_t;
0248 public:
0249 typedef boost::interprocess::version_type<private_node_allocator, 2> version;
0250
0251 template<class T2>
0252 struct rebind
0253 {
0254 typedef private_node_allocator
0255 <T2, SegmentManager, NodesPerBlock> other;
0256 };
0257
0258 private_node_allocator(SegmentManager *segment_mngr)
0259 : base_t(segment_mngr)
0260 {}
0261
0262 template<class T2>
0263 private_node_allocator
0264 (const private_node_allocator<T2, SegmentManager, NodesPerBlock> &other)
0265 : base_t(other)
0266 {}
0267
0268 #else
0269 public:
0270 typedef implementation_defined::segment_manager segment_manager;
0271 typedef segment_manager::void_pointer void_pointer;
0272 typedef implementation_defined::pointer pointer;
0273 typedef implementation_defined::const_pointer const_pointer;
0274 typedef T value_type;
0275 typedef typename ipcdetail::add_reference
0276 <value_type>::type reference;
0277 typedef typename ipcdetail::add_reference
0278 <const value_type>::type const_reference;
0279 typedef typename segment_manager::size_type size_type;
0280 typedef typename segment_manage::difference_type difference_type;
0281
0282
0283
0284 template<class T2>
0285 struct rebind
0286 {
0287 typedef private_node_allocator
0288 <T2, SegmentManager, NodesPerBlock> other;
0289 };
0290
0291 private:
0292
0293
0294 template<class T2, class SegmentManager2, std::size_t N2>
0295 private_node_allocator& operator=
0296 (const private_node_allocator<T2, SegmentManager2, N2>&);
0297
0298
0299
0300 private_node_allocator& operator=(const private_node_allocator&);
0301
0302 public:
0303
0304
0305
0306 private_node_allocator(segment_manager *segment_mngr);
0307
0308
0309
0310 private_node_allocator(const private_node_allocator &other);
0311
0312
0313
0314
0315 template<class T2>
0316 private_node_allocator
0317 (const private_node_allocator<T2, SegmentManager, NodesPerBlock> &other);
0318
0319
0320
0321 ~private_node_allocator();
0322
0323
0324
0325 node_pool_t* get_node_pool() const;
0326
0327
0328
0329 segment_manager* get_segment_manager()const;
0330
0331
0332
0333 size_type max_size() const;
0334
0335
0336
0337 pointer allocate(size_type count, cvoid_pointer hint = 0);
0338
0339
0340
0341 void deallocate(const pointer &ptr, size_type count);
0342
0343
0344
0345 void deallocate_free_blocks();
0346
0347
0348
0349 friend void swap(self_t &alloc1, self_t &alloc2);
0350
0351
0352
0353 pointer address(reference value) const;
0354
0355
0356
0357 const_pointer address(const_reference value) const;
0358
0359
0360
0361 void construct(const pointer &ptr, const_reference v);
0362
0363
0364
0365 void destroy(const pointer &ptr);
0366
0367
0368
0369
0370 size_type size(const pointer &p) const;
0371
0372 pointer allocation_command(boost::interprocess::allocation_type command,
0373 size_type limit_size, size_type &prefer_in_recvd_out_size, pointer &reuse);
0374
0375
0376
0377
0378
0379
0380
0381 void allocate_many(size_type elem_size, size_type num_elements, multiallocation_chain &chain);
0382
0383
0384
0385
0386 void allocate_many(const size_type *elem_sizes, size_type n_elements, multiallocation_chain &chain);
0387
0388
0389
0390
0391
0392
0393
0394 void deallocate_many(multiallocation_chain &chain);
0395
0396
0397
0398
0399 pointer allocate_one();
0400
0401
0402
0403
0404
0405
0406
0407 void allocate_individual(size_type num_elements, multiallocation_chain &chain);
0408
0409
0410
0411
0412 void deallocate_one(const pointer &p);
0413
0414
0415
0416
0417
0418
0419
0420 void deallocate_individual(multiallocation_chain &chain);
0421 #endif
0422 };
0423
0424 #ifdef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0425
0426
0427
0428 template<class T, class S, std::size_t NodesPerBlock, std::size_t F, unsigned char OP> inline
0429 bool operator==(const private_node_allocator<T, S, NodesPerBlock, F, OP> &alloc1,
0430 const private_node_allocator<T, S, NodesPerBlock, F, OP> &alloc2);
0431
0432
0433
0434 template<class T, class S, std::size_t NodesPerBlock, std::size_t F, unsigned char OP> inline
0435 bool operator!=(const private_node_allocator<T, S, NodesPerBlock, F, OP> &alloc1,
0436 const private_node_allocator<T, S, NodesPerBlock, F, OP> &alloc2);
0437
0438 #endif
0439
0440 }
0441 }
0442
0443 #include <boost/interprocess/detail/config_end.hpp>
0444
0445 #endif
0446