Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-10 08:49:23

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_MANAGED_WINDOWS_SHARED_MEMORY_HPP
0012 #define BOOST_INTERPROCESS_MANAGED_WINDOWS_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 #include <boost/interprocess/detail/managed_open_or_create_impl.hpp>
0026 #include <boost/interprocess/detail/managed_memory_impl.hpp>
0027 #include <boost/interprocess/creation_tags.hpp>
0028 #include <boost/interprocess/windows_shared_memory.hpp>
0029 #include <boost/interprocess/permissions.hpp>
0030 #include <boost/move/utility_core.hpp>
0031 //These includes needed to fulfill default template parameters of
0032 //predeclarations in interprocess_fwd.hpp
0033 #include <boost/interprocess/mem_algo/rbtree_best_fit.hpp>
0034 #include <boost/interprocess/sync/mutex_family.hpp>
0035 #include <boost/interprocess/indexes/iset_index.hpp>
0036 
0037 namespace boost {
0038 namespace interprocess {
0039 
0040 namespace ipcdetail {
0041 
0042 template
0043       <
0044          class CharType,
0045          class AllocationAlgorithm,
0046          template<class IndexConfig> class IndexType
0047       >
0048 struct wshmem_open_or_create
0049 {
0050    static const std::size_t segment_manager_alignment = boost::move_detail::alignment_of
0051          < segment_manager
0052                < CharType
0053                , AllocationAlgorithm
0054                , IndexType>
0055          >::value;
0056    static const std::size_t final_segment_manager_alignment
0057       = segment_manager_alignment > AllocationAlgorithm::Alignment
0058       ? segment_manager_alignment : AllocationAlgorithm::Alignment;
0059 
0060    typedef  ipcdetail::managed_open_or_create_impl
0061       < windows_shared_memory
0062       , final_segment_manager_alignment
0063       , false
0064       , false> type;
0065 };
0066 
0067 
0068 }  //namespace ipcdetail {
0069 
0070 //!A basic managed windows shared memory creation class. Initializes the
0071 //!shared memory segment. Inherits all basic functionality from
0072 //!basic_managed_memory_impl<CharType, AllocationAlgorithm, IndexType>
0073 //!Unlike basic_managed_shared_memory, it has
0074 //!no kernel persistence and the shared memory is destroyed
0075 //!when all processes destroy all their windows_shared_memory
0076 //!objects and mapped regions for the same shared memory
0077 //!or the processes end/crash.
0078 //!
0079 //!Warning: basic_managed_windows_shared_memory and
0080 //!basic_managed_shared_memory can't communicate between them.
0081 template
0082       <
0083          class CharType,
0084          class AllocationAlgorithm,
0085          template<class IndexConfig> class IndexType
0086       >
0087 class basic_managed_windows_shared_memory
0088    : public ipcdetail::basic_managed_memory_impl
0089       < CharType, AllocationAlgorithm, IndexType
0090       , ipcdetail::wshmem_open_or_create
0091          <CharType, AllocationAlgorithm, IndexType>::type::ManagedOpenOrCreateUserOffset>
0092 {
0093    #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0094    private:
0095    typedef ipcdetail::basic_managed_memory_impl
0096       < CharType, AllocationAlgorithm, IndexType
0097       , ipcdetail::wshmem_open_or_create
0098          <CharType, AllocationAlgorithm, IndexType>::type::ManagedOpenOrCreateUserOffset>   base_t;
0099    typedef ipcdetail::create_open_func<base_t>        create_open_func_t;
0100 
0101    basic_managed_windows_shared_memory *get_this_pointer()
0102    {  return this;   }
0103 
0104    private:
0105    typedef typename base_t::char_ptr_holder_t   char_ptr_holder_t;
0106    BOOST_MOVABLE_BUT_NOT_COPYABLE(basic_managed_windows_shared_memory)
0107    #endif   //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0108 
0109    public: //functions
0110    typedef typename base_t::size_type              size_type;
0111 
0112    //!Default constructor. Does nothing.
0113    //!Useful in combination with move semantics
0114    basic_managed_windows_shared_memory() BOOST_NOEXCEPT
0115    {}
0116 
0117    //!Creates shared memory and creates and places the segment manager.
0118    //!This can throw.
0119    basic_managed_windows_shared_memory
0120       (create_only_t, const char *name,
0121      size_type size, const void *addr = 0, const permissions &perm = permissions())
0122       : m_wshm(create_only, name, size, read_write, addr,
0123                 create_open_func_t(get_this_pointer(), ipcdetail::DoCreate), perm)
0124    {}
0125 
0126    //!Creates shared memory and creates and places the segment manager if
0127    //!segment was not created. If segment was created it connects to the
0128    //!segment.
0129    //!This can throw.
0130    basic_managed_windows_shared_memory
0131       (open_or_create_t,
0132       const char *name, size_type size,
0133       const void *addr = 0,
0134       const permissions &perm = permissions())
0135       : m_wshm(open_or_create, name, size, read_write, addr,
0136                 create_open_func_t(get_this_pointer(),
0137                 ipcdetail::DoOpenOrCreate), perm)
0138    {}
0139 
0140    //!Connects to a created shared memory and its segment manager.
0141    //!This can throw.
0142    basic_managed_windows_shared_memory
0143       (open_only_t, const char* name, const void *addr = 0)
0144       : m_wshm(open_only, name, read_write, addr,
0145                 create_open_func_t(get_this_pointer(),
0146                 ipcdetail::DoOpen))
0147    {}
0148 
0149    //!Connects to a created shared memory and its segment manager
0150    //!in copy_on_write mode.
0151    //!This can throw.
0152    basic_managed_windows_shared_memory
0153       (open_copy_on_write_t, const char* name, const void *addr = 0)
0154       : m_wshm(open_only, name, copy_on_write, addr,
0155                 create_open_func_t(get_this_pointer(), ipcdetail::DoOpen))
0156    {}
0157 
0158    //!Connects to a created shared memory and its segment manager
0159    //!in read-only mode.
0160    //!This can throw.
0161    basic_managed_windows_shared_memory
0162       (open_read_only_t, const char* name, const void *addr = 0)
0163       : base_t()
0164       , m_wshm(open_only, name, read_only, addr,
0165                 create_open_func_t(get_this_pointer(), ipcdetail::DoOpen))
0166    {}
0167 
0168    //!Creates shared memory and creates and places the segment manager if
0169    //!segment was not created. If segment was created it connects to the
0170    //!segment.
0171    //!This can throw.
0172    basic_managed_windows_shared_memory
0173       (open_or_create_t,
0174       const wchar_t *name, size_type size,
0175       const void *addr = 0,
0176       const permissions &perm = permissions())
0177       : m_wshm(open_or_create, name, size, read_write, addr,
0178                 create_open_func_t(get_this_pointer(),
0179                 ipcdetail::DoOpenOrCreate), perm)
0180    {}
0181 
0182    //!Connects to a created shared memory and its segment manager.
0183    //!This can throw.
0184    basic_managed_windows_shared_memory
0185       (open_only_t, const wchar_t* name, const void *addr = 0)
0186       : m_wshm(open_only, name, read_write, addr,
0187                 create_open_func_t(get_this_pointer(),
0188                 ipcdetail::DoOpen))
0189    {}
0190 
0191    //!Connects to a created shared memory and its segment manager
0192    //!in copy_on_write mode.
0193    //!This can throw.
0194    basic_managed_windows_shared_memory
0195       (open_copy_on_write_t, const wchar_t* name, const void *addr = 0)
0196       : m_wshm(open_only, name, copy_on_write, addr,
0197                 create_open_func_t(get_this_pointer(), ipcdetail::DoOpen))
0198    {}
0199 
0200    //!Connects to a created shared memory and its segment manager
0201    //!in read-only mode.
0202    //!This can throw.
0203    basic_managed_windows_shared_memory
0204       (open_read_only_t, const wchar_t* name, const void *addr = 0)
0205       : base_t()
0206       , m_wshm(open_only, name, read_only, addr,
0207                 create_open_func_t(get_this_pointer(), ipcdetail::DoOpen))
0208    {}
0209 
0210    //!Moves the ownership of "moved"'s managed memory to *this.
0211    //!Does not throw
0212    basic_managed_windows_shared_memory
0213       (BOOST_RV_REF(basic_managed_windows_shared_memory) moved) BOOST_NOEXCEPT
0214    {  this->swap(moved);   }
0215 
0216    //!Moves the ownership of "moved"'s managed memory to *this.
0217    //!Does not throw
0218    basic_managed_windows_shared_memory &operator=(BOOST_RV_REF(basic_managed_windows_shared_memory) moved) BOOST_NOEXCEPT
0219    {
0220       basic_managed_windows_shared_memory tmp(boost::move(moved));
0221       this->swap(tmp);
0222       return *this;
0223    }
0224 
0225    //!Destroys *this and indicates that the calling process is finished using
0226    //!the resource. All mapped regions are still valid after
0227    //!destruction. When all mapped regions and basic_managed_windows_shared_memory
0228    //!objects referring the shared memory are destroyed, the
0229    //!operating system will destroy the shared memory.
0230    ~basic_managed_windows_shared_memory()
0231    {}
0232 
0233    //!Swaps the ownership of the managed mapped memories managed by *this and other.
0234    //!Never throws.
0235    void swap(basic_managed_windows_shared_memory &other) BOOST_NOEXCEPT
0236    {
0237       base_t::swap(other);
0238       m_wshm.swap(other.m_wshm);
0239    }
0240 
0241    #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0242 
0243    //!Tries to find a previous named allocation address. Returns a memory
0244    //!buffer and the object count. If not found returned pointer is 0.
0245    //!Never throws.
0246    template <class T>
0247    std::pair<T*, size_type> find  (char_ptr_holder_t name)
0248    {
0249       if(m_wshm.get_mapped_region().get_mode() == read_only){
0250          return base_t::template find_no_lock<T>(name);
0251       }
0252       else{
0253          return base_t::template find<T>(name);
0254       }
0255    }
0256 
0257    private:
0258    typename ipcdetail::wshmem_open_or_create
0259       <CharType, AllocationAlgorithm, IndexType>::type m_wshm;
0260    #endif   //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0261 };
0262 
0263 #ifdef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0264 
0265 //!Typedef for a default basic_managed_windows_shared_memory
0266 //!of narrow characters
0267 typedef basic_managed_windows_shared_memory
0268    <char
0269    ,rbtree_best_fit<mutex_family>
0270    ,iset_index>
0271 managed_windows_shared_memory;
0272 
0273 //!Typedef for a default basic_managed_windows_shared_memory
0274 //!of wide characters
0275 typedef basic_managed_windows_shared_memory
0276    <wchar_t
0277    ,rbtree_best_fit<mutex_family>
0278    ,iset_index>
0279 wmanaged_windows_shared_memory;
0280 
0281 #endif   //#ifdef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0282 
0283 
0284 }  //namespace interprocess {
0285 }  //namespace boost {
0286 
0287 #include <boost/interprocess/detail/config_end.hpp>
0288 
0289 #endif   //BOOST_INTERPROCESS_MANAGED_WINDOWS_SHARED_MEMORY_HPP