]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/smart_ptr/detail/lwm_win32_cs.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / smart_ptr / detail / lwm_win32_cs.hpp
CommitLineData
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
29struct _RTL_CRITICAL_SECTION;
30
7c673cae
FG
31#endif
32
33namespace boost
34{
35
36namespace detail
37{
38
39#ifndef BOOST_USE_WINDOWS_H
40
41struct 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 56extern "C" __declspec(dllimport) void __stdcall InitializeCriticalSectionEx(::_RTL_CRITICAL_SECTION *, unsigned long, unsigned long);
7c673cae 57#else
b32b8144 58extern "C" __declspec(dllimport) void __stdcall InitializeCriticalSection(::_RTL_CRITICAL_SECTION *);
7c673cae 59#endif
b32b8144
FG
60extern "C" __declspec(dllimport) void __stdcall EnterCriticalSection(::_RTL_CRITICAL_SECTION *);
61extern "C" __declspec(dllimport) void __stdcall LeaveCriticalSection(::_RTL_CRITICAL_SECTION *);
62extern "C" __declspec(dllimport) void __stdcall DeleteCriticalSection(::_RTL_CRITICAL_SECTION *);
7c673cae 63
92f5a8d4
TL
64typedef ::_RTL_CRITICAL_SECTION rtl_critical_section;
65
66#else // #ifndef BOOST_USE_WINDOWS_H
7c673cae
FG
67
68typedef ::CRITICAL_SECTION critical_section;
69
b32b8144
FG
70#if BOOST_PLAT_WINDOWS_RUNTIME
71using ::InitializeCriticalSectionEx;
72#else
73using ::InitializeCriticalSection;
74#endif
75using ::EnterCriticalSection;
76using ::LeaveCriticalSection;
77using ::DeleteCriticalSection;
78
92f5a8d4
TL
79typedef ::CRITICAL_SECTION rtl_critical_section;
80
7c673cae
FG
81#endif // #ifndef BOOST_USE_WINDOWS_H
82
83class lightweight_mutex
84{
85private:
86
87 critical_section cs_;
88
89 lightweight_mutex(lightweight_mutex const &);
90 lightweight_mutex & operator=(lightweight_mutex const &);
91
92public:
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