]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/smart_ptr/detail/lwm_win32_cs.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / smart_ptr / detail / lwm_win32_cs.hpp
1 #ifndef BOOST_SMART_PTR_DETAIL_LWM_WIN32_CS_HPP_INCLUDED
2 #define BOOST_SMART_PTR_DETAIL_LWM_WIN32_CS_HPP_INCLUDED
3
4 // MS compatible compilers support #pragma once
5
6 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
7 # pragma once
8 #endif
9
10 //
11 // boost/detail/lwm_win32_cs.hpp
12 //
13 // Copyright (c) 2002, 2003 Peter Dimov
14 // Copyright (c) Microsoft Corporation 2014
15 //
16 // Distributed under the Boost Software License, Version 1.0. (See
17 // accompanying file LICENSE_1_0.txt or copy at
18 // http://www.boost.org/LICENSE_1_0.txt)
19 //
20
21 #include <boost/predef.h>
22
23 #ifdef BOOST_USE_WINDOWS_H
24
25 #include <windows.h>
26
27 #else
28
29 struct _RTL_CRITICAL_SECTION;
30
31 #endif
32
33 namespace boost
34 {
35
36 namespace detail
37 {
38
39 #ifndef BOOST_USE_WINDOWS_H
40
41 struct critical_section
42 {
43 struct critical_section_debug * DebugInfo;
44 long LockCount;
45 long RecursionCount;
46 void * OwningThread;
47 void * LockSemaphore;
48 #if defined(_WIN64)
49 unsigned __int64 SpinCount;
50 #else
51 unsigned long SpinCount;
52 #endif
53 };
54
55 #if BOOST_PLAT_WINDOWS_RUNTIME
56 extern "C" __declspec(dllimport) void __stdcall InitializeCriticalSectionEx(::_RTL_CRITICAL_SECTION *, unsigned long, unsigned long);
57 #else
58 extern "C" __declspec(dllimport) void __stdcall InitializeCriticalSection(::_RTL_CRITICAL_SECTION *);
59 #endif
60 extern "C" __declspec(dllimport) void __stdcall EnterCriticalSection(::_RTL_CRITICAL_SECTION *);
61 extern "C" __declspec(dllimport) void __stdcall LeaveCriticalSection(::_RTL_CRITICAL_SECTION *);
62 extern "C" __declspec(dllimport) void __stdcall DeleteCriticalSection(::_RTL_CRITICAL_SECTION *);
63
64 #else
65
66 typedef ::CRITICAL_SECTION critical_section;
67
68 #if BOOST_PLAT_WINDOWS_RUNTIME
69 using ::InitializeCriticalSectionEx;
70 #else
71 using ::InitializeCriticalSection;
72 #endif
73 using ::EnterCriticalSection;
74 using ::LeaveCriticalSection;
75 using ::DeleteCriticalSection;
76
77 #endif // #ifndef BOOST_USE_WINDOWS_H
78
79 class lightweight_mutex
80 {
81 private:
82
83 critical_section cs_;
84
85 lightweight_mutex(lightweight_mutex const &);
86 lightweight_mutex & operator=(lightweight_mutex const &);
87
88 public:
89
90 lightweight_mutex()
91 {
92 #if BOOST_PLAT_WINDOWS_RUNTIME
93 boost::detail::InitializeCriticalSectionEx(reinterpret_cast< ::_RTL_CRITICAL_SECTION* >(&cs_), 4000, 0);
94 #else
95 boost::detail::InitializeCriticalSection(reinterpret_cast< ::_RTL_CRITICAL_SECTION* >(&cs_));
96 #endif
97 }
98
99 ~lightweight_mutex()
100 {
101 boost::detail::DeleteCriticalSection(reinterpret_cast< ::_RTL_CRITICAL_SECTION* >(&cs_));
102 }
103
104 class scoped_lock;
105 friend class scoped_lock;
106
107 class scoped_lock
108 {
109 private:
110
111 lightweight_mutex & m_;
112
113 scoped_lock(scoped_lock const &);
114 scoped_lock & operator=(scoped_lock const &);
115
116 public:
117
118 explicit scoped_lock(lightweight_mutex & m): m_(m)
119 {
120 boost::detail::EnterCriticalSection(reinterpret_cast< ::_RTL_CRITICAL_SECTION* >(&m_.cs_));
121 }
122
123 ~scoped_lock()
124 {
125 boost::detail::LeaveCriticalSection(reinterpret_cast< ::_RTL_CRITICAL_SECTION* >(&m_.cs_));
126 }
127 };
128 };
129
130 } // namespace detail
131
132 } // namespace boost
133
134 #endif // #ifndef BOOST_SMART_PTR_DETAIL_LWM_WIN32_CS_HPP_INCLUDED