1 //////////////////////////////////////////////////////////////////////////////
3 // (C) Copyright Ion Gaztanaga 2009-2012. Distributed under the Boost
4 // Software License, Version 1.0. (See accompanying file
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 // See http://www.boost.org/libs/interprocess for documentation.
9 //////////////////////////////////////////////////////////////////////////////
11 #ifndef BOOST_INTERPROCESS_BASIC_GLOBAL_MEMORY_HPP
12 #define BOOST_INTERPROCESS_BASIC_GLOBAL_MEMORY_HPP
14 #ifndef BOOST_CONFIG_HPP
15 # include <boost/config.hpp>
18 #if defined(BOOST_HAS_PRAGMA_ONCE)
22 #include <boost/interprocess/detail/config_begin.hpp>
23 #include <boost/interprocess/detail/workaround.hpp>
25 #include <boost/interprocess/offset_ptr.hpp>
26 #include <boost/interprocess/sync/spin/mutex.hpp>
27 #include <boost/interprocess/sync/spin/recursive_mutex.hpp>
28 #include <boost/interprocess/detail/managed_memory_impl.hpp>
29 #include <boost/interprocess/detail/managed_open_or_create_impl.hpp>
30 #include <boost/interprocess/mem_algo/rbtree_best_fit.hpp>
31 #include <boost/interprocess/indexes/iset_index.hpp>
32 #include <boost/interprocess/creation_tags.hpp>
33 #include <boost/interprocess/permissions.hpp>
36 namespace interprocess{
39 struct intermodule_singleton_mutex_family
41 typedef boost::interprocess::ipcdetail::spin_mutex mutex_type;
42 typedef boost::interprocess::ipcdetail::spin_recursive_mutex recursive_mutex_type;
45 struct intermodule_types
47 //We must use offset_ptr since a loaded DLL can map the singleton holder shared memory
48 //at a different address than other DLLs or the main executable
49 typedef rbtree_best_fit<intermodule_singleton_mutex_family, offset_ptr<void> > mem_algo;
50 template<class Device, bool FileBased>
53 typedef managed_open_or_create_impl
54 <Device, mem_algo::Alignment, FileBased, false> type;
58 //we must implement our own managed shared memory to avoid circular dependencies
59 template<class Device, bool FileBased>
60 class basic_managed_global_memory
61 : public basic_managed_memory_impl
63 , intermodule_types::mem_algo
65 , intermodule_types::open_or_create<Device, FileBased>::type::ManagedOpenOrCreateUserOffset
67 , private intermodule_types::open_or_create<Device, FileBased>::type
69 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
70 typedef typename intermodule_types::template open_or_create<Device, FileBased>::type base2_t;
72 typedef basic_managed_memory_impl
74 , intermodule_types::mem_algo
76 , base2_t::ManagedOpenOrCreateUserOffset
79 typedef create_open_func<base_t> create_open_func_t;
81 basic_managed_global_memory *get_this_pointer()
85 typedef typename base_t::size_type size_type;
88 typedef typename base_t::char_ptr_holder_t char_ptr_holder_t;
89 BOOST_MOVABLE_BUT_NOT_COPYABLE(basic_managed_global_memory)
90 #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
94 basic_managed_global_memory (open_or_create_t,
95 const char *name, size_type size,
96 const void *addr = 0, const permissions& perm = permissions())
98 , base2_t(open_or_create_t(), name, size, read_write, addr,
99 create_open_func_t(get_this_pointer(),
100 DoOpenOrCreate), perm)
103 basic_managed_global_memory (open_only_t , const char* name,
104 const void *addr = 0)
106 , base2_t(open_only_t(), name, read_write, addr,
107 create_open_func_t(get_this_pointer(),
113 } //namespace ipcdetail{
114 } //namespace interprocess{
117 #include <boost/interprocess/detail/config_end.hpp>
119 #endif //#ifndef BOOST_INTERPROCESS_BASIC_GLOBAL_MEMORY_HPP