Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-03-30 08:05:01

0001 //////////////////////////////////////////////////////////////////////////////
0002 //
0003 // (C) Copyright Ion Gaztanaga 2008-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_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 ">#
0019 #if defined(BOOST_HAS_PRAGMA_ONCE)
0020 #  pragma once
0021 #endif
0022 
0023 #include <boost/interprocess/detail/config_begin.hpp>
0024 #include <boost/interprocess/detail/workaround.hpp>
0025 
0026 #if !defined(BOOST_INTERPROCESS_XSI_SHARED_MEMORY_OBJECTS)
0027 #error "This header can't be used in operating systems without XSI (System V) shared memory support"
0028 #endif
0029 
0030 #include <boost/interprocess/detail/managed_memory_impl.hpp>
0031 #include <boost/interprocess/detail/managed_open_or_create_impl.hpp>
0032 #include <boost/interprocess/detail/xsi_shared_memory_file_wrapper.hpp>
0033 #include <boost/interprocess/creation_tags.hpp>
0034 //These includes needed to fulfill default template parameters of
0035 //predeclarations in interprocess_fwd.hpp
0036 #include <boost/interprocess/mem_algo/rbtree_best_fit.hpp>
0037 #include <boost/interprocess/sync/mutex_family.hpp>
0038 #include <boost/interprocess/indexes/iset_index.hpp>
0039 
0040 namespace boost {
0041 
0042 namespace interprocess {
0043 
0044 namespace ipcdetail {
0045 
0046 template
0047       <
0048          class CharType,
0049          class AllocationAlgorithm,
0050          template<class IndexConfig> class IndexType
0051       >
0052 struct xsishmem_open_or_create
0053 {
0054    static const std::size_t segment_manager_alignment = boost::move_detail::alignment_of
0055          < segment_manager
0056                < CharType
0057                , AllocationAlgorithm
0058                , IndexType>
0059          >::value;
0060    static const std::size_t final_segment_manager_alignment
0061       = segment_manager_alignment > AllocationAlgorithm::Alignment
0062       ? segment_manager_alignment : AllocationAlgorithm::Alignment;
0063 
0064    typedef  ipcdetail::managed_open_or_create_impl
0065       < xsi_shared_memory_file_wrapper
0066       , final_segment_manager_alignment
0067       , false
0068       , true> type;
0069 };
0070 
0071 
0072 }  //namespace ipcdetail {
0073 
0074 //!A basic X/Open System Interface (XSI) shared memory named object creation class. Initializes the
0075 //!shared memory segment. Inherits all basic functionality from
0076 //!basic_managed_memory_impl<CharType, AllocationAlgorithm, IndexType>
0077 template
0078       <
0079          class CharType,
0080          class AllocationAlgorithm,
0081          template<class IndexConfig> class IndexType
0082       >
0083 class basic_managed_xsi_shared_memory
0084    : public ipcdetail::basic_managed_memory_impl
0085       <CharType, AllocationAlgorithm, IndexType
0086       ,ipcdetail::xsishmem_open_or_create<CharType, AllocationAlgorithm, IndexType>
0087          ::type::ManagedOpenOrCreateUserOffset>
0088    , private ipcdetail::xsishmem_open_or_create
0089       <CharType, AllocationAlgorithm, IndexType>::type
0090 {
0091    #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0092    public:
0093    typedef xsi_shared_memory_file_wrapper device_type;
0094 
0095    public:
0096    typedef typename ipcdetail::xsishmem_open_or_create
0097       <CharType, AllocationAlgorithm, IndexType>::type base2_t;
0098    typedef ipcdetail::basic_managed_memory_impl
0099       <CharType, AllocationAlgorithm, IndexType,
0100       base2_t::ManagedOpenOrCreateUserOffset>          base_t;
0101 
0102    typedef ipcdetail::create_open_func<base_t>        create_open_func_t;
0103 
0104    basic_managed_xsi_shared_memory *get_this_pointer()
0105    {  return this;   }
0106 
0107    private:
0108    typedef typename base_t::char_ptr_holder_t   char_ptr_holder_t;
0109    BOOST_MOVABLE_BUT_NOT_COPYABLE(basic_managed_xsi_shared_memory)
0110    #endif   //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0111 
0112    public: //functions
0113    typedef typename base_t::size_type              size_type;
0114 
0115    //!Destroys *this and indicates that the calling process is finished using
0116    //!the resource. The destructor function will deallocate
0117    //!any system resources allocated by the system for use by this process for
0118    //!this resource. The resource can still be opened again calling
0119    //!the open constructor overload. To erase the resource from the system
0120    //!use remove().
0121    ~basic_managed_xsi_shared_memory()
0122    {}
0123 
0124    //!Default constructor. Does nothing.
0125    //!Useful in combination with move semantics
0126    basic_managed_xsi_shared_memory() BOOST_NOEXCEPT
0127    {}
0128 
0129    //!Creates shared memory and creates and places the segment manager.
0130    //!This can throw.
0131    basic_managed_xsi_shared_memory(create_only_t, const xsi_key &key,
0132                              std::size_t size, const void *addr = 0, const permissions& perm = permissions())
0133       : base_t()
0134       , base2_t(create_only, key, size, read_write, addr,
0135                 create_open_func_t(get_this_pointer(), ipcdetail::DoCreate), perm)
0136    {}
0137 
0138    //!Creates shared memory and creates and places the segment manager if
0139    //!segment was not created. If segment was created it connects to the
0140    //!segment.
0141    //!This can throw.
0142    basic_managed_xsi_shared_memory (open_or_create_t,
0143                               const xsi_key &key, std::size_t size,
0144                               const void *addr = 0, const permissions& perm = permissions())
0145       : base_t()
0146       , base2_t(open_or_create, key, size, read_write, addr,
0147                 create_open_func_t(get_this_pointer(),
0148                 ipcdetail::DoOpenOrCreate), perm)
0149    {}
0150 
0151    //!Connects to a created shared memory and its segment manager.
0152    //!in read-only mode.
0153    //!This can throw.
0154    basic_managed_xsi_shared_memory (open_read_only_t, const xsi_key &key,
0155                                 const void *addr = 0)
0156       : base_t()
0157       , base2_t(open_only, key, read_only, addr,
0158                 create_open_func_t(get_this_pointer(),
0159                 ipcdetail::DoOpen))
0160    {}
0161 
0162    //!Connects to a created shared memory and its segment manager.
0163    //!This can throw.
0164    basic_managed_xsi_shared_memory (open_only_t, const xsi_key &key,
0165                                 const void *addr = 0)
0166       : base_t()
0167       , base2_t(open_only, key, read_write, addr,
0168                 create_open_func_t(get_this_pointer(),
0169                 ipcdetail::DoOpen))
0170    {}
0171 
0172    //!Moves the ownership of "moved"'s managed memory to *this.
0173    //!Does not throw
0174    basic_managed_xsi_shared_memory(BOOST_RV_REF(basic_managed_xsi_shared_memory) moved) BOOST_NOEXCEPT
0175    {
0176       basic_managed_xsi_shared_memory tmp;
0177       this->swap(moved);
0178       tmp.swap(moved);
0179    }
0180 
0181    //!Moves the ownership of "moved"'s managed memory to *this.
0182    //!Does not throw
0183    basic_managed_xsi_shared_memory &operator=(BOOST_RV_REF(basic_managed_xsi_shared_memory) moved) BOOST_NOEXCEPT
0184    {
0185       basic_managed_xsi_shared_memory tmp(boost::move(moved));
0186       this->swap(tmp);
0187       return *this;
0188    }
0189 
0190    //!Swaps the ownership of the managed shared memories managed by *this and other.
0191    //!Never throws.
0192    void swap(basic_managed_xsi_shared_memory &other) BOOST_NOEXCEPT
0193    {
0194       base_t::swap(other);
0195       base2_t::swap(other);
0196    }
0197 
0198    //!Erases a XSI shared memory object identified by shmid
0199    //!from the system.
0200    //!Returns false on error. Never throws
0201    static bool remove(int shmid)
0202    {  return device_type::remove(shmid); }
0203 
0204    int get_shmid() const BOOST_NOEXCEPT
0205    {  return base2_t::get_device().get_shmid(); }
0206 
0207    #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0208 
0209    //!Tries to find a previous named allocation address. Returns a memory
0210    //!buffer and the object count. If not found returned pointer is 0.
0211    //!Never throws.
0212    template <class T>
0213    std::pair<T*, std::size_t> find  (char_ptr_holder_t name)
0214    {
0215       if(base2_t::get_mapped_region().get_mode() == read_only){
0216          return base_t::template find_no_lock<T>(name);
0217       }
0218       else{
0219          return base_t::template find<T>(name);
0220       }
0221    }
0222 
0223    #endif   //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0224 };
0225 
0226 #ifdef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0227 
0228 //!Typedef for a default basic_managed_xsi_shared_memory
0229 //!of narrow characters
0230 typedef basic_managed_xsi_shared_memory
0231    <char
0232    ,rbtree_best_fit<mutex_family>
0233    ,iset_index>
0234 managed_xsi_shared_memory;
0235 
0236 //!Typedef for a default basic_managed_xsi_shared_memory
0237 //!of wide characters
0238 typedef basic_managed_xsi_shared_memory
0239    <wchar_t
0240    ,rbtree_best_fit<mutex_family>
0241    ,iset_index>
0242 wmanaged_xsi_shared_memory;
0243 
0244 #endif   //#ifdef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0245 
0246 }  //namespace interprocess {
0247 }  //namespace boost {
0248 
0249 #include <boost/interprocess/detail/config_end.hpp>
0250 
0251 #endif   //BOOST_INTERPROCESS_MANAGED_XSI_SHARED_MEMORY_HPP
0252