Chris@16
|
1 //////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
2 //
|
Chris@16
|
3 // (C) Copyright Ion Gaztanaga 2009-2012. Distributed under the Boost
|
Chris@16
|
4 // Software License, Version 1.0. (See accompanying file
|
Chris@16
|
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
6 //
|
Chris@16
|
7 // See http://www.boost.org/libs/interprocess for documentation.
|
Chris@16
|
8 //
|
Chris@16
|
9 //////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
10
|
Chris@16
|
11 #ifndef BOOST_INTERPROCESS_BASIC_GLOBAL_MEMORY_HPP
|
Chris@16
|
12 #define BOOST_INTERPROCESS_BASIC_GLOBAL_MEMORY_HPP
|
Chris@16
|
13
|
Chris@101
|
14 #ifndef BOOST_CONFIG_HPP
|
Chris@101
|
15 # include <boost/config.hpp>
|
Chris@101
|
16 #endif
|
Chris@101
|
17 #
|
Chris@101
|
18 #if defined(BOOST_HAS_PRAGMA_ONCE)
|
Chris@16
|
19 #pragma once
|
Chris@16
|
20 #endif
|
Chris@16
|
21
|
Chris@16
|
22 #include <boost/interprocess/detail/config_begin.hpp>
|
Chris@16
|
23 #include <boost/interprocess/detail/workaround.hpp>
|
Chris@16
|
24
|
Chris@16
|
25 #include <boost/interprocess/offset_ptr.hpp>
|
Chris@16
|
26 #include <boost/interprocess/sync/spin/mutex.hpp>
|
Chris@16
|
27 #include <boost/interprocess/sync/spin/recursive_mutex.hpp>
|
Chris@16
|
28 #include <boost/interprocess/detail/managed_memory_impl.hpp>
|
Chris@16
|
29 #include <boost/interprocess/detail/managed_open_or_create_impl.hpp>
|
Chris@16
|
30 #include <boost/interprocess/mem_algo/rbtree_best_fit.hpp>
|
Chris@16
|
31 #include <boost/interprocess/indexes/iset_index.hpp>
|
Chris@16
|
32 #include <boost/interprocess/creation_tags.hpp>
|
Chris@16
|
33 #include <boost/interprocess/permissions.hpp>
|
Chris@16
|
34
|
Chris@16
|
35 namespace boost{
|
Chris@16
|
36 namespace interprocess{
|
Chris@16
|
37 namespace ipcdetail{
|
Chris@16
|
38
|
Chris@16
|
39 struct intermodule_singleton_mutex_family
|
Chris@16
|
40 {
|
Chris@16
|
41 typedef boost::interprocess::ipcdetail::spin_mutex mutex_type;
|
Chris@16
|
42 typedef boost::interprocess::ipcdetail::spin_recursive_mutex recursive_mutex_type;
|
Chris@16
|
43 };
|
Chris@16
|
44
|
Chris@16
|
45 struct intermodule_types
|
Chris@16
|
46 {
|
Chris@16
|
47 //We must use offset_ptr since a loaded DLL can map the singleton holder shared memory
|
Chris@16
|
48 //at a different address than other DLLs or the main executable
|
Chris@16
|
49 typedef rbtree_best_fit<intermodule_singleton_mutex_family, offset_ptr<void> > mem_algo;
|
Chris@16
|
50 template<class Device, bool FileBased>
|
Chris@16
|
51 struct open_or_create
|
Chris@16
|
52 {
|
Chris@16
|
53 typedef managed_open_or_create_impl
|
Chris@16
|
54 <Device, mem_algo::Alignment, FileBased, false> type;
|
Chris@16
|
55 };
|
Chris@16
|
56 };
|
Chris@16
|
57
|
Chris@16
|
58 //we must implement our own managed shared memory to avoid circular dependencies
|
Chris@16
|
59 template<class Device, bool FileBased>
|
Chris@16
|
60 class basic_managed_global_memory
|
Chris@16
|
61 : public basic_managed_memory_impl
|
Chris@16
|
62 < char
|
Chris@16
|
63 , intermodule_types::mem_algo
|
Chris@16
|
64 , iset_index
|
Chris@16
|
65 , intermodule_types::open_or_create<Device, FileBased>::type::ManagedOpenOrCreateUserOffset
|
Chris@16
|
66 >
|
Chris@16
|
67 , private intermodule_types::open_or_create<Device, FileBased>::type
|
Chris@16
|
68 {
|
Chris@101
|
69 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
|
Chris@16
|
70 typedef typename intermodule_types::template open_or_create<Device, FileBased>::type base2_t;
|
Chris@16
|
71
|
Chris@16
|
72 typedef basic_managed_memory_impl
|
Chris@16
|
73 < char
|
Chris@16
|
74 , intermodule_types::mem_algo
|
Chris@16
|
75 , iset_index
|
Chris@16
|
76 , base2_t::ManagedOpenOrCreateUserOffset
|
Chris@16
|
77 > base_t;
|
Chris@16
|
78
|
Chris@16
|
79 typedef create_open_func<base_t> create_open_func_t;
|
Chris@16
|
80
|
Chris@16
|
81 basic_managed_global_memory *get_this_pointer()
|
Chris@16
|
82 { return this; }
|
Chris@16
|
83
|
Chris@16
|
84 public:
|
Chris@16
|
85 typedef typename base_t::size_type size_type;
|
Chris@16
|
86
|
Chris@16
|
87 private:
|
Chris@16
|
88 typedef typename base_t::char_ptr_holder_t char_ptr_holder_t;
|
Chris@16
|
89 BOOST_MOVABLE_BUT_NOT_COPYABLE(basic_managed_global_memory)
|
Chris@101
|
90 #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
|
Chris@16
|
91
|
Chris@16
|
92 public: //functions
|
Chris@16
|
93
|
Chris@16
|
94 basic_managed_global_memory (open_or_create_t open_or_create,
|
Chris@16
|
95 const char *name, size_type size,
|
Chris@16
|
96 const void *addr = 0, const permissions& perm = permissions())
|
Chris@16
|
97 : base_t()
|
Chris@16
|
98 , base2_t(open_or_create, name, size, read_write, addr,
|
Chris@16
|
99 create_open_func_t(get_this_pointer(),
|
Chris@16
|
100 DoOpenOrCreate), perm)
|
Chris@16
|
101 {}
|
Chris@16
|
102
|
Chris@16
|
103 basic_managed_global_memory (open_only_t open_only, const char* name,
|
Chris@16
|
104 const void *addr = 0)
|
Chris@16
|
105 : base_t()
|
Chris@16
|
106 , base2_t(open_only, name, read_write, addr,
|
Chris@16
|
107 create_open_func_t(get_this_pointer(),
|
Chris@16
|
108 DoOpen))
|
Chris@16
|
109 {}
|
Chris@16
|
110 };
|
Chris@16
|
111
|
Chris@16
|
112
|
Chris@16
|
113 } //namespace ipcdetail{
|
Chris@16
|
114 } //namespace interprocess{
|
Chris@16
|
115 } //namespace boost{
|
Chris@16
|
116
|
Chris@16
|
117 #include <boost/interprocess/detail/config_end.hpp>
|
Chris@16
|
118
|
Chris@16
|
119 #endif //#ifndef BOOST_INTERPROCESS_BASIC_GLOBAL_MEMORY_HPP
|