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
18 #include <boost/interprocess/detail/config_begin.hpp>
19 #include <boost/interprocess/detail/workaround.hpp>
21 #include <boost/interprocess/offset_ptr.hpp>
22 #include <boost/interprocess/sync/spin/mutex.hpp>
23 #include <boost/interprocess/sync/spin/recursive_mutex.hpp>
24 #include <boost/interprocess/detail/managed_memory_impl.hpp>
25 #include <boost/interprocess/detail/managed_open_or_create_impl.hpp>
26 #include <boost/interprocess/mem_algo/rbtree_best_fit.hpp>
27 #include <boost/interprocess/indexes/iset_index.hpp>
28 #include <boost/interprocess/creation_tags.hpp>
29 #include <boost/interprocess/permissions.hpp>
32 namespace interprocess{
35 struct intermodule_singleton_mutex_family
37 typedef boost::interprocess::ipcdetail::spin_mutex mutex_type;
38 typedef boost::interprocess::ipcdetail::spin_recursive_mutex recursive_mutex_type;
41 struct intermodule_types
43 //We must use offset_ptr since a loaded DLL can map the singleton holder shared memory
44 //at a different address than other DLLs or the main executable
45 typedef rbtree_best_fit<intermodule_singleton_mutex_family, offset_ptr<void> > mem_algo;
46 template<class Device, bool FileBased>
49 typedef managed_open_or_create_impl
50 <Device, mem_algo::Alignment, FileBased, false> type;
54 //we must implement our own managed shared memory to avoid circular dependencies
55 template<class Device, bool FileBased>
56 class basic_managed_global_memory
57 : public basic_managed_memory_impl
59 , intermodule_types::mem_algo
61 , intermodule_types::open_or_create<Device, FileBased>::type::ManagedOpenOrCreateUserOffset
63 , private intermodule_types::open_or_create<Device, FileBased>::type
65 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
66 typedef typename intermodule_types::template open_or_create<Device, FileBased>::type base2_t;
68 typedef basic_managed_memory_impl
70 , intermodule_types::mem_algo
72 , base2_t::ManagedOpenOrCreateUserOffset
75 typedef create_open_func<base_t> create_open_func_t;
77 basic_managed_global_memory *get_this_pointer()
81 typedef typename base_t::size_type size_type;
84 typedef typename base_t::char_ptr_holder_t char_ptr_holder_t;
85 BOOST_MOVABLE_BUT_NOT_COPYABLE(basic_managed_global_memory)
86 #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
90 basic_managed_global_memory (open_or_create_t open_or_create,
91 const char *name, size_type size,
92 const void *addr = 0, const permissions& perm = permissions())
94 , base2_t(open_or_create, name, size, read_write, addr,
95 create_open_func_t(get_this_pointer(),
96 DoOpenOrCreate), perm)
99 basic_managed_global_memory (open_only_t open_only, const char* name,
100 const void *addr = 0)
102 , base2_t(open_only, name, read_write, addr,
103 create_open_func_t(get_this_pointer(),
109 } //namespace ipcdetail{
110 } //namespace interprocess{
113 #include <boost/interprocess/detail/config_end.hpp>
115 #endif //#ifndef BOOST_INTERPROCESS_BASIC_GLOBAL_MEMORY_HPP