Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-22 10:09:04

0001 //////////////////////////////////////////////////////////////////////////////
0002 //
0003 // (C) Copyright Ion Gaztanaga 2005-2012. Distributed under the Boost
0004 // Software License, Version 1.0. (See accompanying file
0005 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 // See http://www.boost.org/libs/interprocess for documentation.
0008 //
0009 //////////////////////////////////////////////////////////////////////////////
0010 
0011 #ifndef BOOST_INTERPROCESS_CACHED_NODE_ALLOCATOR_HPP
0012 #define BOOST_INTERPROCESS_CACHED_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/interprocess/interprocess_fwd.hpp>
0026 #include <boost/interprocess/allocators/detail/node_pool.hpp>
0027 #include <boost/interprocess/allocators/detail/allocator_common.hpp>
0028 #include <boost/interprocess/detail/workaround.hpp>
0029 #include <boost/interprocess/detail/utilities.hpp>
0030 #include <boost/interprocess/containers/version_type.hpp>
0031 #include <boost/interprocess/allocators/detail/node_tools.hpp>
0032 #include <cstddef>
0033 
0034 //!\file
0035 //!Describes cached_cached_node_allocator pooled shared memory STL compatible allocator
0036 
0037 namespace boost {
0038 namespace interprocess {
0039 
0040 
0041 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0042 
0043 namespace ipcdetail {
0044 
0045 template < class T
0046          , class SegmentManager
0047          , std::size_t NodesPerBlock = 64
0048          >
0049 class cached_node_allocator_v1
0050    :  public ipcdetail::cached_allocator_impl
0051          < T
0052          , ipcdetail::shared_node_pool
0053             < SegmentManager
0054             , sizeof_value<T>::value
0055             , NodesPerBlock
0056             >
0057          , 1>
0058 {
0059    public:
0060    typedef ipcdetail::cached_allocator_impl
0061          < T
0062          , ipcdetail::shared_node_pool
0063             < SegmentManager
0064             , sizeof_value<T>::value
0065             , NodesPerBlock
0066             >
0067          , 1> base_t;
0068 
0069    template<class T2>
0070    struct rebind
0071    {
0072       typedef cached_node_allocator_v1
0073          <T2, SegmentManager, NodesPerBlock>  other;
0074    };
0075 
0076    typedef typename base_t::size_type size_type;
0077 
0078    cached_node_allocator_v1(SegmentManager *segment_mngr,
0079                          size_type max_cached_nodes = base_t::DEFAULT_MAX_CACHED_NODES)
0080       : base_t(segment_mngr, max_cached_nodes)
0081    {}
0082 
0083    template<class T2>
0084    cached_node_allocator_v1
0085       (const cached_node_allocator_v1
0086          <T2, SegmentManager, NodesPerBlock> &other)
0087       : base_t(other)
0088    {}
0089 };
0090 
0091 }  //namespace ipcdetail{
0092 
0093 #endif   //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0094 
0095 template < class T
0096          , class SegmentManager
0097          , std::size_t NodesPerBlock
0098          >
0099 class cached_node_allocator
0100    #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0101    :  public ipcdetail::cached_allocator_impl
0102          < T
0103          , ipcdetail::shared_node_pool
0104             < SegmentManager
0105             , sizeof_value<T>::value
0106             , NodesPerBlock
0107             >
0108          , 2>
0109    #endif   //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0110 {
0111 
0112    #ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0113    public:
0114    typedef ipcdetail::cached_allocator_impl
0115          < T
0116          , ipcdetail::shared_node_pool
0117             < SegmentManager
0118             , sizeof_value<T>::value
0119             , NodesPerBlock
0120             >
0121          , 2> base_t;
0122 
0123    public:
0124    typedef boost::interprocess::version_type<cached_node_allocator, 2>   version;
0125    typedef typename base_t::size_type size_type;
0126 
0127    template<class T2>
0128    struct rebind
0129    {
0130       typedef cached_node_allocator<T2, SegmentManager, NodesPerBlock>  other;
0131    };
0132 
0133    cached_node_allocator(SegmentManager *segment_mngr,
0134                          size_type max_cached_nodes = base_t::DEFAULT_MAX_CACHED_NODES)
0135       : base_t(segment_mngr, max_cached_nodes)
0136    {}
0137 
0138    template<class T2>
0139    cached_node_allocator
0140       (const cached_node_allocator<T2, SegmentManager, NodesPerBlock> &other)
0141       : base_t(other)
0142    {}
0143 
0144    #else
0145    public:
0146    typedef implementation_defined::segment_manager       segment_manager;
0147    typedef segment_manager::void_pointer                 void_pointer;
0148    typedef implementation_defined::pointer               pointer;
0149    typedef implementation_defined::const_pointer         const_pointer;
0150    typedef T                                             value_type;
0151    typedef typename ipcdetail::add_reference
0152                      <value_type>::type                  reference;
0153    typedef typename ipcdetail::add_reference
0154                      <const value_type>::type            const_reference;
0155    typedef typename SegmentManager::size_type            size_type;
0156    typedef typename SegmentManager::difference_type      difference_type;
0157 
0158    //!Obtains cached_node_allocator from
0159    //!cached_node_allocator
0160    template<class T2>
0161    struct rebind
0162    {
0163       typedef cached_node_allocator<T2, SegmentManager> other;
0164    };
0165 
0166    private:
0167    //!Not assignable from
0168    //!related cached_node_allocator
0169    template<class T2, class SegmentManager2, std::size_t N2>
0170    cached_node_allocator& operator=
0171       (const cached_node_allocator<T2, SegmentManager2, N2>&);
0172 
0173    //!Not assignable from
0174    //!other cached_node_allocator
0175    cached_node_allocator& operator=(const cached_node_allocator&);
0176 
0177    public:
0178    //!Constructor from a segment manager. If not present, constructs a node
0179    //!pool. Increments the reference count of the associated node pool.
0180    //!Can throw boost::interprocess::bad_alloc
0181    cached_node_allocator(segment_manager *segment_mngr);
0182 
0183    //!Copy constructor from other cached_node_allocator. Increments the reference
0184    //!count of the associated node pool. Never throws
0185    cached_node_allocator(const cached_node_allocator &other);
0186 
0187    //!Copy constructor from related cached_node_allocator. If not present, constructs
0188    //!a node pool. Increments the reference count of the associated node pool.
0189    //!Can throw boost::interprocess::bad_alloc
0190    template<class T2>
0191    cached_node_allocator
0192       (const cached_node_allocator<T2, SegmentManager, NodesPerBlock> &other);
0193 
0194    //!Destructor, removes node_pool_t from memory
0195    //!if its reference count reaches to zero. Never throws
0196    ~cached_node_allocator();
0197 
0198    //!Returns a pointer to the node pool.
0199    //!Never throws
0200    node_pool_t* get_node_pool() const;
0201 
0202    //!Returns the segment manager.
0203    //!Never throws
0204    segment_manager* get_segment_manager()const;
0205 
0206    //!Returns the number of elements that could be allocated.
0207    //!Never throws
0208    size_type max_size() const;
0209 
0210    //!Allocate memory for an array of count elements.
0211    //!Throws boost::interprocess::bad_alloc if there is no enough memory
0212    pointer allocate(size_type count, cvoid_pointer hint = 0);
0213 
0214    //!Deallocate allocated memory.
0215    //!Never throws
0216    void deallocate(const pointer &ptr, size_type count);
0217 
0218    //!Deallocates all free blocks
0219    //!of the pool
0220    void deallocate_free_blocks();
0221 
0222    //!Swaps allocators. Does not throw. If each allocator is placed in a
0223    //!different memory segment, the result is undefined.
0224    friend void swap(self_t &alloc1, self_t &alloc2);
0225 
0226    //!Returns address of mutable object.
0227    //!Never throws
0228    pointer address(reference value) const;
0229 
0230    //!Returns address of non mutable object.
0231    //!Never throws
0232    const_pointer address(const_reference value) const;
0233 
0234    //!Default construct an object.
0235    //!Throws if T's default constructor throws
0236    void construct(const pointer &ptr, const_reference v);
0237 
0238    //!Destroys object. Throws if object's
0239    //!destructor throws
0240    void destroy(const pointer &ptr);
0241 
0242    //!Returns maximum the number of objects the previously allocated memory
0243    //!pointed by p can hold. This size only works for memory allocated with
0244    //!allocate, allocation_command and allocate_many.
0245    size_type size(const pointer &p) const;
0246 
0247    pointer allocation_command(boost::interprocess::allocation_type command,
0248                            size_type limit_size, size_type &prefer_in_recvd_out_size, pointer &reuse);
0249 
0250    //!Allocates many elements of size elem_size in a contiguous block
0251    //!of memory. The minimum number to be allocated is min_elements,
0252    //!the preferred and maximum number is
0253    //!preferred_elements. The number of actually allocated elements is
0254    //!will be assigned to received_size. The elements must be deallocated
0255    //!with deallocate(...)
0256    void allocate_many(size_type elem_size, size_type num_elements, multiallocation_chain &chain);
0257 
0258    //!Allocates n_elements elements, each one of size elem_sizes[i]in a
0259    //!contiguous block
0260    //!of memory. The elements must be deallocated
0261    void allocate_many(const size_type *elem_sizes, size_type n_elements, multiallocation_chain &chain);
0262 
0263    //!Allocates many elements of size elem_size in a contiguous block
0264    //!of memory. The minimum number to be allocated is min_elements,
0265    //!the preferred and maximum number is
0266    //!preferred_elements. The number of actually allocated elements is
0267    //!will be assigned to received_size. The elements must be deallocated
0268    //!with deallocate(...)
0269    void deallocate_many(multiallocation_chain &chain);
0270 
0271    //!Allocates just one object. Memory allocated with this function
0272    //!must be deallocated only with deallocate_one().
0273    //!Throws boost::interprocess::bad_alloc if there is no enough memory
0274    pointer allocate_one();
0275 
0276    //!Allocates many elements of size == 1 in a contiguous block
0277    //!of memory. The minimum number to be allocated is min_elements,
0278    //!the preferred and maximum number is
0279    //!preferred_elements. The number of actually allocated elements is
0280    //!will be assigned to received_size. Memory allocated with this function
0281    //!must be deallocated only with deallocate_one().
0282    multiallocation_chain allocate_individual(size_type num_elements);
0283 
0284    //!Deallocates memory previously allocated with allocate_one().
0285    //!You should never use deallocate_one to deallocate memory allocated
0286    //!with other functions different from allocate_one(). Never throws
0287    void deallocate_one(const pointer &p);
0288 
0289    //!Allocates many elements of size == 1 in a contiguous block
0290    //!of memory. The minimum number to be allocated is min_elements,
0291    //!the preferred and maximum number is
0292    //!preferred_elements. The number of actually allocated elements is
0293    //!will be assigned to received_size. Memory allocated with this function
0294    //!must be deallocated only with deallocate_one().
0295    void deallocate_individual(multiallocation_chain it);
0296    //!Sets the new max cached nodes value. This can provoke deallocations
0297    //!if "newmax" is less than current cached nodes. Never throws
0298    void set_max_cached_nodes(size_type newmax);
0299 
0300    //!Returns the max cached nodes parameter.
0301    //!Never throws
0302    size_type get_max_cached_nodes() const;
0303    #endif
0304 };
0305 
0306 #ifdef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0307 
0308 //!Equality test for same type
0309 //!of cached_node_allocator
0310 template<class T, class S, std::size_t NPC> inline
0311 bool operator==(const cached_node_allocator<T, S, NPC> &alloc1,
0312                 const cached_node_allocator<T, S, NPC> &alloc2);
0313 
0314 //!Inequality test for same type
0315 //!of cached_node_allocator
0316 template<class T, class S, std::size_t NPC> inline
0317 bool operator!=(const cached_node_allocator<T, S, NPC> &alloc1,
0318                 const cached_node_allocator<T, S, NPC> &alloc2);
0319 
0320 #endif
0321 
0322 }  //namespace interprocess {
0323 }  //namespace boost {
0324 
0325 #include <boost/interprocess/detail/config_end.hpp>
0326 
0327 #endif   //#ifndef BOOST_INTERPROCESS_CACHED_NODE_ALLOCATOR_HPP
0328