]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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 | |
b32b8144 FG |
24 | |
25 | #include <windows.h> | |
26 | ||
27 | #else | |
28 | ||
29 | struct _RTL_CRITICAL_SECTION; | |
30 | ||
7c673cae FG |
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 | |
b32b8144 | 56 | extern "C" __declspec(dllimport) void __stdcall InitializeCriticalSectionEx(::_RTL_CRITICAL_SECTION *, unsigned long, unsigned long); |
7c673cae | 57 | #else |
b32b8144 | 58 | extern "C" __declspec(dllimport) void __stdcall InitializeCriticalSection(::_RTL_CRITICAL_SECTION *); |
7c673cae | 59 | #endif |
b32b8144 FG |
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 *); | |
7c673cae | 63 | |
92f5a8d4 TL |
64 | typedef ::_RTL_CRITICAL_SECTION rtl_critical_section; |
65 | ||
66 | #else // #ifndef BOOST_USE_WINDOWS_H | |
7c673cae FG |
67 | |
68 | typedef ::CRITICAL_SECTION critical_section; | |
69 | ||
b32b8144 FG |
70 | #if BOOST_PLAT_WINDOWS_RUNTIME |
71 | using ::InitializeCriticalSectionEx; | |
72 | #else | |
73 | using ::InitializeCriticalSection; | |
74 | #endif | |
75 | using ::EnterCriticalSection; | |
76 | using ::LeaveCriticalSection; | |
77 | using ::DeleteCriticalSection; | |
78 | ||
92f5a8d4 TL |
79 | typedef ::CRITICAL_SECTION rtl_critical_section; |
80 | ||
7c673cae FG |
81 | #endif // #ifndef BOOST_USE_WINDOWS_H |
82 | ||
83 | class lightweight_mutex | |
84 | { | |
85 | private: | |
86 | ||
87 | critical_section cs_; | |
88 | ||
89 | lightweight_mutex(lightweight_mutex const &); | |
90 | lightweight_mutex & operator=(lightweight_mutex const &); | |
91 | ||
92 | public: | |
93 | ||
94 | lightweight_mutex() | |
95 | { | |
96 | #if BOOST_PLAT_WINDOWS_RUNTIME | |
92f5a8d4 | 97 | boost::detail::InitializeCriticalSectionEx(reinterpret_cast< rtl_critical_section* >(&cs_), 4000, 0); |
7c673cae | 98 | #else |
92f5a8d4 | 99 | boost::detail::InitializeCriticalSection(reinterpret_cast< rtl_critical_section* >(&cs_)); |
7c673cae FG |
100 | #endif |
101 | } | |
102 | ||
103 | ~lightweight_mutex() | |
104 | { | |
92f5a8d4 | 105 | boost::detail::DeleteCriticalSection(reinterpret_cast< rtl_critical_section* >(&cs_)); |
7c673cae FG |
106 | } |
107 | ||
108 | class scoped_lock; | |
109 | friend class scoped_lock; | |
110 | ||
111 | class scoped_lock | |
112 | { | |
113 | private: | |
114 | ||
115 | lightweight_mutex & m_; | |
116 | ||
117 | scoped_lock(scoped_lock const &); | |
118 | scoped_lock & operator=(scoped_lock const &); | |
119 | ||
120 | public: | |
121 | ||
122 | explicit scoped_lock(lightweight_mutex & m): m_(m) | |
123 | { | |
92f5a8d4 | 124 | boost::detail::EnterCriticalSection(reinterpret_cast< rtl_critical_section* >(&m_.cs_)); |
7c673cae FG |
125 | } |
126 | ||
127 | ~scoped_lock() | |
128 | { | |
92f5a8d4 | 129 | boost::detail::LeaveCriticalSection(reinterpret_cast< rtl_critical_section* >(&m_.cs_)); |
7c673cae FG |
130 | } |
131 | }; | |
132 | }; | |
133 | ||
134 | } // namespace detail | |
135 | ||
136 | } // namespace boost | |
137 | ||
138 | #endif // #ifndef BOOST_SMART_PTR_DETAIL_LWM_WIN32_CS_HPP_INCLUDED |