Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:38:34

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 #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 //These includes needed to fulfill default template parameters of
0034 //predeclarations in interprocess_fwd.hpp
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 }  //namespace ipcdetail {
0072 
0073 //!A basic X/Open System Interface (XSI) shared memory named object creation class. Initializes the
0074 //!shared memory segment. Inherits all basic functionality from
0075 //!basic_managed_memory_impl<CharType, AllocationAlgorithm, IndexType>
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   //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0110 
0111    public: //functions
0112    typedef typename base_t::size_type              size_type;
0113 
0114    //!Destroys *this and indicates that the calling process is finished using
0115    //!the resource. The destructor function will deallocate
0116    //!any system resources allocated by the system for use by this process for
0117    //!this resource. The resource can still be opened again calling
0118    //!the open constructor overload. To erase the resource from the system
0119    //!use remove().
0120    ~basic_managed_xsi_shared_memory()
0121    {}
0122 
0123    //!Default constructor. Does nothing.
0124    //!Useful in combination with move semantics
0125    basic_managed_xsi_shared_memory() BOOST_NOEXCEPT
0126    {}
0127 
0128    //!Creates shared memory and creates and places the segment manager.
0129    //!This can throw.
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    //!Creates shared memory and creates and places the segment manager if
0138    //!segment was not created. If segment was created it connects to the
0139    //!segment.
0140    //!This can throw.
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    //!Connects to a created shared memory and its segment manager.
0151    //!in read-only mode.
0152    //!This can throw.
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    //!Connects to a created shared memory and its segment manager.
0162    //!This can throw.
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    //!Moves the ownership of "moved"'s managed memory to *this.
0172    //!Does not throw
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    //!Moves the ownership of "moved"'s managed memory to *this.
0181    //!Does not throw
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    //!Swaps the ownership of the managed shared memories managed by *this and other.
0190    //!Never throws.
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    //!Erases a XSI shared memory object identified by shmid
0198    //!from the system.
0199    //!Returns false on error. Never throws
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    //!Tries to find a previous named allocation address. Returns a memory
0209    //!buffer and the object count. If not found returned pointer is 0.
0210    //!Never throws.
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   //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0223 };
0224 
0225 #ifdef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0226 
0227 //!Typedef for a default basic_managed_xsi_shared_memory
0228 //!of narrow characters
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 //!Typedef for a default basic_managed_xsi_shared_memory
0236 //!of wide characters
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   //#ifdef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0244 
0245 }  //namespace interprocess {
0246 }  //namespace boost {
0247 
0248 #include <boost/interprocess/detail/config_end.hpp>
0249 
0250 #endif   //BOOST_INTERPROCESS_MANAGED_XSI_SHARED_MEMORY_HPP
0251