File indexing completed on 2025-10-30 08:20:55
0001 
0002 
0003 
0004 
0005 
0006 
0007 
0008 
0009 
0010 
0011 #ifndef BOOST_INTERPROCESS_MANAGED_XSI_SHARED_MEMORY_HPP
0012 #define BOOST_INTERPROCESS_MANAGED_XSI_SHARED_MEMORY_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 #if !defined(BOOST_INTERPROCESS_XSI_SHARED_MEMORY_OBJECTS)
0026 #error "This header can't be used in operating systems without XSI (System V) shared memory support"
0027 #endif
0028 
0029 #include <boost/interprocess/detail/managed_memory_impl.hpp>
0030 #include <boost/interprocess/detail/managed_open_or_create_impl.hpp>
0031 #include <boost/interprocess/detail/xsi_shared_memory_file_wrapper.hpp>
0032 #include <boost/interprocess/creation_tags.hpp>
0033 
0034 
0035 #include <boost/interprocess/mem_algo/rbtree_best_fit.hpp>
0036 #include <boost/interprocess/sync/mutex_family.hpp>
0037 #include <boost/interprocess/indexes/iset_index.hpp>
0038 
0039 namespace boost {
0040 
0041 namespace interprocess {
0042 
0043 namespace ipcdetail {
0044 
0045 template
0046       <
0047          class CharType,
0048          class AllocationAlgorithm,
0049          template<class IndexConfig> class IndexType
0050       >
0051 struct xsishmem_open_or_create
0052 {
0053    static const std::size_t segment_manager_alignment = boost::move_detail::alignment_of
0054          < segment_manager
0055                < CharType
0056                , AllocationAlgorithm
0057                , IndexType>
0058          >::value;
0059    static const std::size_t final_segment_manager_alignment
0060       = segment_manager_alignment > AllocationAlgorithm::Alignment
0061       ? segment_manager_alignment : AllocationAlgorithm::Alignment;
0062 
0063    typedef  ipcdetail::managed_open_or_create_impl
0064       < xsi_shared_memory_file_wrapper
0065       , final_segment_manager_alignment
0066       , false
0067       , true> type;
0068 };
0069 
0070 
0071 }  
0072 
0073 
0074 
0075 
0076 template
0077       <
0078          class CharType,
0079          class AllocationAlgorithm,
0080          template<class IndexConfig> class IndexType
0081       >
0082 class basic_managed_xsi_shared_memory
0083    : public ipcdetail::basic_managed_memory_impl
0084       <CharType, AllocationAlgorithm, IndexType
0085       ,ipcdetail::xsishmem_open_or_create<CharType, AllocationAlgorithm, IndexType>
0086          ::type::ManagedOpenOrCreateUserOffset>
0087    , private ipcdetail::xsishmem_open_or_create
0088       <CharType, AllocationAlgorithm, IndexType>::type
0089 {
0090    #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0091    public:
0092    typedef xsi_shared_memory_file_wrapper device_type;
0093 
0094    public:
0095    typedef typename ipcdetail::xsishmem_open_or_create
0096       <CharType, AllocationAlgorithm, IndexType>::type base2_t;
0097    typedef ipcdetail::basic_managed_memory_impl
0098       <CharType, AllocationAlgorithm, IndexType,
0099       base2_t::ManagedOpenOrCreateUserOffset>          base_t;
0100 
0101    typedef ipcdetail::create_open_func<base_t>        create_open_func_t;
0102 
0103    basic_managed_xsi_shared_memory *get_this_pointer()
0104    {  return this;   }
0105 
0106    private:
0107    typedef typename base_t::char_ptr_holder_t   char_ptr_holder_t;
0108    BOOST_MOVABLE_BUT_NOT_COPYABLE(basic_managed_xsi_shared_memory)
0109    #endif   
0110 
0111    public: 
0112    typedef typename base_t::size_type              size_type;
0113 
0114    
0115    
0116    
0117    
0118    
0119    
0120    ~basic_managed_xsi_shared_memory()
0121    {}
0122 
0123    
0124    
0125    basic_managed_xsi_shared_memory() BOOST_NOEXCEPT
0126    {}
0127 
0128    
0129    
0130    basic_managed_xsi_shared_memory(create_only_t, const xsi_key &key,
0131                              std::size_t size, const void *addr = 0, const permissions& perm = permissions())
0132       : base_t()
0133       , base2_t(create_only, key, size, read_write, addr,
0134                 create_open_func_t(get_this_pointer(), ipcdetail::DoCreate), perm)
0135    {}
0136 
0137    
0138    
0139    
0140    
0141    basic_managed_xsi_shared_memory (open_or_create_t,
0142                               const xsi_key &key, std::size_t size,
0143                               const void *addr = 0, const permissions& perm = permissions())
0144       : base_t()
0145       , base2_t(open_or_create, key, size, read_write, addr,
0146                 create_open_func_t(get_this_pointer(),
0147                 ipcdetail::DoOpenOrCreate), perm)
0148    {}
0149 
0150    
0151    
0152    
0153    basic_managed_xsi_shared_memory (open_read_only_t, const xsi_key &key,
0154                                 const void *addr = 0)
0155       : base_t()
0156       , base2_t(open_only, key, read_only, addr,
0157                 create_open_func_t(get_this_pointer(),
0158                 ipcdetail::DoOpen))
0159    {}
0160 
0161    
0162    
0163    basic_managed_xsi_shared_memory (open_only_t, const xsi_key &key,
0164                                 const void *addr = 0)
0165       : base_t()
0166       , base2_t(open_only, key, read_write, addr,
0167                 create_open_func_t(get_this_pointer(),
0168                 ipcdetail::DoOpen))
0169    {}
0170 
0171    
0172    
0173    basic_managed_xsi_shared_memory(BOOST_RV_REF(basic_managed_xsi_shared_memory) moved) BOOST_NOEXCEPT
0174    {
0175       basic_managed_xsi_shared_memory tmp;
0176       this->swap(moved);
0177       tmp.swap(moved);
0178    }
0179 
0180    
0181    
0182    basic_managed_xsi_shared_memory &operator=(BOOST_RV_REF(basic_managed_xsi_shared_memory) moved) BOOST_NOEXCEPT
0183    {
0184       basic_managed_xsi_shared_memory tmp(boost::move(moved));
0185       this->swap(tmp);
0186       return *this;
0187    }
0188 
0189    
0190    
0191    void swap(basic_managed_xsi_shared_memory &other) BOOST_NOEXCEPT
0192    {
0193       base_t::swap(other);
0194       base2_t::swap(other);
0195    }
0196 
0197    
0198    
0199    
0200    static bool remove(int shmid)
0201    {  return device_type::remove(shmid); }
0202 
0203    int get_shmid() const BOOST_NOEXCEPT
0204    {  return base2_t::get_device().get_shmid(); }
0205 
0206    #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0207 
0208    
0209    
0210    
0211    template <class T>
0212    std::pair<T*, std::size_t> find  (char_ptr_holder_t name)
0213    {
0214       if(base2_t::get_mapped_region().get_mode() == read_only){
0215          return base_t::template find_no_lock<T>(name);
0216       }
0217       else{
0218          return base_t::template find<T>(name);
0219       }
0220    }
0221 
0222    #endif   
0223 };
0224 
0225 #ifdef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0226 
0227 
0228 
0229 typedef basic_managed_xsi_shared_memory
0230    <char
0231    ,rbtree_best_fit<mutex_family>
0232    ,iset_index>
0233 managed_xsi_shared_memory;
0234 
0235 
0236 
0237 typedef basic_managed_xsi_shared_memory
0238    <wchar_t
0239    ,rbtree_best_fit<mutex_family>
0240    ,iset_index>
0241 wmanaged_xsi_shared_memory;
0242 
0243 #endif   
0244 
0245 }  
0246 }  
0247 
0248 #include <boost/interprocess/detail/config_end.hpp>
0249 
0250 #endif   
0251