comparison DEPENDENCIES/generic/include/boost/interprocess/mapped_region.hpp @ 101:c530137014c0

Update Boost headers (1.58.0)
author Chris Cannam
date Mon, 07 Sep 2015 11:12:49 +0100
parents 2665513ce2d3
children
comparison
equal deleted inserted replaced
100:793467b5e61c 101:c530137014c0
9 ////////////////////////////////////////////////////////////////////////////// 9 //////////////////////////////////////////////////////////////////////////////
10 10
11 #ifndef BOOST_INTERPROCESS_MAPPED_REGION_HPP 11 #ifndef BOOST_INTERPROCESS_MAPPED_REGION_HPP
12 #define BOOST_INTERPROCESS_MAPPED_REGION_HPP 12 #define BOOST_INTERPROCESS_MAPPED_REGION_HPP
13 13
14 #ifndef BOOST_CONFIG_HPP
15 # include <boost/config.hpp>
16 #endif
17 #
18 #if defined(BOOST_HAS_PRAGMA_ONCE)
19 # pragma once
20 #endif
21
14 #include <boost/interprocess/detail/config_begin.hpp> 22 #include <boost/interprocess/detail/config_begin.hpp>
15 #include <boost/interprocess/detail/workaround.hpp> 23 #include <boost/interprocess/detail/workaround.hpp>
16 24
17 #include <boost/interprocess/interprocess_fwd.hpp> 25 #include <boost/interprocess/interprocess_fwd.hpp>
18 #include <boost/interprocess/exceptions.hpp> 26 #include <boost/interprocess/exceptions.hpp>
19 #include <boost/move/move.hpp> 27 #include <boost/move/utility_core.hpp>
20 #include <boost/interprocess/detail/utilities.hpp> 28 #include <boost/interprocess/detail/utilities.hpp>
21 #include <boost/interprocess/detail/os_file_functions.hpp> 29 #include <boost/interprocess/detail/os_file_functions.hpp>
22 #include <string> 30 #include <string>
23 #include <boost/cstdint.hpp> 31 #include <boost/cstdint.hpp>
24 #include <boost/assert.hpp> 32 #include <boost/assert.hpp>
33 #include <boost/move/adl_move_swap.hpp>
34
25 //Some Unixes use caddr_t instead of void * in madvise 35 //Some Unixes use caddr_t instead of void * in madvise
26 // SunOS Tru64 HP-UX AIX 36 // SunOS Tru64 HP-UX AIX
27 #if defined(sun) || defined(__sun) || defined(__osf__) || defined(__osf) || defined(_hpux) || defined(hpux) || defined(_AIX) 37 #if defined(sun) || defined(__sun) || defined(__osf__) || defined(__osf) || defined(_hpux) || defined(hpux) || defined(_AIX)
28 #define BOOST_INTERPROCESS_MADVISE_USES_CADDR_T 38 #define BOOST_INTERPROCESS_MADVISE_USES_CADDR_T
29 #include <sys/types.h> 39 #include <sys/types.h>
51 # include <boost/assert.hpp> 61 # include <boost/assert.hpp>
52 # else 62 # else
53 # error Unknown platform 63 # error Unknown platform
54 # endif 64 # endif
55 65
56 #endif //#if (defined BOOST_INTERPROCESS_WINDOWS) 66 #endif //#if defined (BOOST_INTERPROCESS_WINDOWS)
57 67
58 //!\file 68 //!\file
59 //!Describes mapped region class 69 //!Describes mapped region class
60 70
61 namespace boost { 71 namespace boost {
62 namespace interprocess { 72 namespace interprocess {
63 73
64 /// @cond 74 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
65 75
66 //Solaris declares madvise only in some configurations but defines MADV_XXX, a bit confusing. 76 //Solaris declares madvise only in some configurations but defines MADV_XXX, a bit confusing.
67 //Predeclare it here to avoid any compilation error 77 //Predeclare it here to avoid any compilation error
68 #if (defined(sun) || defined(__sun)) && defined(MADV_NORMAL) 78 #if (defined(sun) || defined(__sun)) && defined(MADV_NORMAL)
69 extern "C" int madvise(caddr_t, size_t, int); 79 extern "C" int madvise(caddr_t, size_t, int);
70 #endif 80 #endif
71 81
72 namespace ipcdetail{ class interprocess_tester; } 82 namespace ipcdetail{ class interprocess_tester; }
73 namespace ipcdetail{ class raw_mapped_region_creator; } 83 namespace ipcdetail{ class raw_mapped_region_creator; }
74 84
75 /// @endcond 85 #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
76 86
77 //!The mapped_region class represents a portion or region created from a 87 //!The mapped_region class represents a portion or region created from a
78 //!memory_mappable object. 88 //!memory_mappable object.
79 //! 89 //!
80 //!The OS can map a region bigger than the requested one, as region must 90 //!The OS can map a region bigger than the requested one, as region must
81 //!be multiple of the page size, but mapped_region will always refer to 91 //!be multiple of the page size, but mapped_region will always refer to
82 //!the region specified by the user. 92 //!the region specified by the user.
83 class mapped_region 93 class mapped_region
84 { 94 {
85 /// @cond 95 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
86 //Non-copyable 96 //Non-copyable
87 BOOST_MOVABLE_BUT_NOT_COPYABLE(mapped_region) 97 BOOST_MOVABLE_BUT_NOT_COPYABLE(mapped_region)
88 /// @endcond 98 #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
89 99
90 public: 100 public:
91 101
92 //!Creates a mapping region of the mapped memory "mapping", starting in 102 //!Creates a mapping region of the mapped memory "mapping", starting in
93 //!offset "offset", and the mapping's size will be "size". The mapping 103 //!offset "offset", and the mapping's size will be "size". The mapping
184 //!Returns true on success. Never throws. 194 //!Returns true on success. Never throws.
185 bool shrink_by(std::size_t bytes, bool from_back = true); 195 bool shrink_by(std::size_t bytes, bool from_back = true);
186 196
187 //!This enum specifies region usage behaviors that an application can specify 197 //!This enum specifies region usage behaviors that an application can specify
188 //!to the mapped region implementation. 198 //!to the mapped region implementation.
189 enum advice_types{ 199 enum advice_types{
190 //!Specifies that the application has no advice to give on its behavior with respect to 200 //!Specifies that the application has no advice to give on its behavior with respect to
191 //!the region. It is the default characteristic if no advice is given for a range of memory. 201 //!the region. It is the default characteristic if no advice is given for a range of memory.
192 advice_normal, 202 advice_normal,
193 //!Specifies that the application expects to access the region sequentially from 203 //!Specifies that the application expects to access the region sequentially from
194 //!lower addresses to higher addresses. The implementation can lower the priority of 204 //!lower addresses to higher addresses. The implementation can lower the priority of
215 //!Returns the size of the page. This size is the minimum memory that 225 //!Returns the size of the page. This size is the minimum memory that
216 //!will be used by the system when mapping a memory mappable source and 226 //!will be used by the system when mapping a memory mappable source and
217 //!will restrict the address and the offset to map. 227 //!will restrict the address and the offset to map.
218 static std::size_t get_page_size(); 228 static std::size_t get_page_size();
219 229
220 /// @cond 230 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
221 private: 231 private:
222 //!Closes a previously opened memory mapping. Never throws 232 //!Closes a previously opened memory mapping. Never throws
223 void priv_close(); 233 void priv_close();
224 234
225 void* priv_map_address() const; 235 void* priv_map_address() const;
252 void dont_close_on_destruction(); 262 void dont_close_on_destruction();
253 #if defined(BOOST_INTERPROCESS_WINDOWS) && !defined(BOOST_INTERPROCESS_FORCE_GENERIC_EMULATION) 263 #if defined(BOOST_INTERPROCESS_WINDOWS) && !defined(BOOST_INTERPROCESS_FORCE_GENERIC_EMULATION)
254 template<int Dummy> 264 template<int Dummy>
255 static void destroy_syncs_in_range(const void *addr, std::size_t size); 265 static void destroy_syncs_in_range(const void *addr, std::size_t size);
256 #endif 266 #endif
257 /// @endcond 267 #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
258 }; 268 };
259 269
260 ///@cond 270 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
261 271
262 inline void swap(mapped_region &x, mapped_region &y) 272 inline void swap(mapped_region &x, mapped_region &y)
263 { x.swap(y); } 273 { x.swap(y); }
264 274
265 inline mapped_region::~mapped_region() 275 inline mapped_region::~mapped_region()
372 382
373 template<int dummy> 383 template<int dummy>
374 inline std::size_t mapped_region::page_size_holder<dummy>::get_page_size() 384 inline std::size_t mapped_region::page_size_holder<dummy>::get_page_size()
375 { 385 {
376 winapi::system_info info; 386 winapi::system_info info;
377 get_system_info(&info); 387 winapi::get_system_info(&info);
378 return std::size_t(info.dwAllocationGranularity); 388 return std::size_t(info.dwAllocationGranularity);
379 } 389 }
380 390
381 template<class MemoryMappable> 391 template<class MemoryMappable>
382 inline mapped_region::mapped_region 392 inline mapped_region::mapped_region
518 if(!this->priv_shrink_param_check(bytes, from_back, shrink_page_start, shrink_page_bytes)){ 528 if(!this->priv_shrink_param_check(bytes, from_back, shrink_page_start, shrink_page_bytes)){
519 return false; 529 return false;
520 } 530 }
521 else if(shrink_page_bytes){ 531 else if(shrink_page_bytes){
522 //In Windows, we can't decommit the storage or release the virtual address space, 532 //In Windows, we can't decommit the storage or release the virtual address space,
523 //the best we can do is try to remove some memory from the process working set. 533 //the best we can do is try to remove some memory from the process working set.
524 //With a bit of luck we can free some physical memory. 534 //With a bit of luck we can free some physical memory.
525 unsigned long old_protect_ignored; 535 unsigned long old_protect_ignored;
526 bool b_ret = winapi::virtual_unlock(shrink_page_start, shrink_page_bytes) 536 bool b_ret = winapi::virtual_unlock(shrink_page_start, shrink_page_bytes)
527 || (winapi::get_last_error() == winapi::error_not_locked); 537 || (winapi::get_last_error() == winapi::error_not_locked);
528 (void)old_protect_ignored; 538 (void)old_protect_ignored;
559 } 569 }
560 570
561 inline void mapped_region::dont_close_on_destruction() 571 inline void mapped_region::dont_close_on_destruction()
562 {} 572 {}
563 573
564 #else //#if (defined BOOST_INTERPROCESS_WINDOWS) 574 #else //#if defined (BOOST_INTERPROCESS_WINDOWS)
565 575
566 inline mapped_region::mapped_region() 576 inline mapped_region::mapped_region()
567 : m_base(0), m_size(0), m_page_offset(0), m_mode(read_only), m_is_xsi(false) 577 : m_base(0), m_size(0), m_page_offset(0), m_mode(read_only), m_is_xsi(false)
568 {} 578 {}
569 579
739 int unix_advice = 0; 749 int unix_advice = 0;
740 //Modes; 0: none, 2: posix, 1: madvise 750 //Modes; 0: none, 2: posix, 1: madvise
741 const unsigned int mode_none = 0; 751 const unsigned int mode_none = 0;
742 const unsigned int mode_padv = 1; 752 const unsigned int mode_padv = 1;
743 const unsigned int mode_madv = 2; 753 const unsigned int mode_madv = 2;
754 // Suppress "unused variable" warnings
755 (void)mode_padv;
756 (void)mode_madv;
744 unsigned int mode = mode_none; 757 unsigned int mode = mode_none;
745 //Choose advice either from POSIX (preferred) or native Unix 758 //Choose advice either from POSIX (preferred) or native Unix
746 switch(advice){ 759 switch(advice){
747 case advice_normal: 760 case advice_normal:
748 #if defined(POSIX_MADV_NORMAL) 761 #if defined(POSIX_MADV_NORMAL)
828 } 841 }
829 842
830 inline void mapped_region::dont_close_on_destruction() 843 inline void mapped_region::dont_close_on_destruction()
831 { m_base = 0; } 844 { m_base = 0; }
832 845
833 #endif //##if (defined BOOST_INTERPROCESS_WINDOWS) 846 #endif //#if defined (BOOST_INTERPROCESS_WINDOWS)
834 847
835 template<int dummy> 848 template<int dummy>
836 const std::size_t mapped_region::page_size_holder<dummy>::PageSize 849 const std::size_t mapped_region::page_size_holder<dummy>::PageSize
837 = mapped_region::page_size_holder<dummy>::get_page_size(); 850 = mapped_region::page_size_holder<dummy>::get_page_size();
838 851
844 return page_size_holder<0>::PageSize; 857 return page_size_holder<0>::PageSize;
845 } 858 }
846 859
847 inline void mapped_region::swap(mapped_region &other) 860 inline void mapped_region::swap(mapped_region &other)
848 { 861 {
849 ipcdetail::do_swap(this->m_base, other.m_base); 862 ::boost::adl_move_swap(this->m_base, other.m_base);
850 ipcdetail::do_swap(this->m_size, other.m_size); 863 ::boost::adl_move_swap(this->m_size, other.m_size);
851 ipcdetail::do_swap(this->m_page_offset, other.m_page_offset); 864 ::boost::adl_move_swap(this->m_page_offset, other.m_page_offset);
852 ipcdetail::do_swap(this->m_mode, other.m_mode); 865 ::boost::adl_move_swap(this->m_mode, other.m_mode);
853 #if (defined BOOST_INTERPROCESS_WINDOWS) 866 #if defined (BOOST_INTERPROCESS_WINDOWS)
854 ipcdetail::do_swap(this->m_file_or_mapping_hnd, other.m_file_or_mapping_hnd); 867 ::boost::adl_move_swap(this->m_file_or_mapping_hnd, other.m_file_or_mapping_hnd);
855 #else 868 #else
856 ipcdetail::do_swap(this->m_is_xsi, other.m_is_xsi); 869 ::boost::adl_move_swap(this->m_is_xsi, other.m_is_xsi);
857 #endif 870 #endif
858 } 871 }
859 872
860 //!No-op functor 873 //!No-op functor
861 struct null_mapped_region_function 874 struct null_mapped_region_function
865 878
866 std::size_t get_min_size() const 879 std::size_t get_min_size() const
867 { return 0; } 880 { return 0; }
868 }; 881 };
869 882
870 /// @endcond 883 #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
871 884
872 } //namespace interprocess { 885 } //namespace interprocess {
873 } //namespace boost { 886 } //namespace boost {
874 887
875 #include <boost/interprocess/detail/config_end.hpp> 888 #include <boost/interprocess/detail/config_end.hpp>