Revert "Ugly, not-to-be-pushed sucking in of all of Boost to get windows to work."
[dyninst.git] / external / boost / detail / lwm_win32_cs.hpp
1 #ifndef BOOST_DETAIL_LWM_WIN32_CS_HPP_INCLUDED\r
2 #define BOOST_DETAIL_LWM_WIN32_CS_HPP_INCLUDED\r
3 \r
4 // MS compatible compilers support #pragma once\r
5 \r
6 #if defined(_MSC_VER) && (_MSC_VER >= 1020)\r
7 # pragma once\r
8 #endif\r
9 \r
10 //\r
11 //  boost/detail/lwm_win32_cs.hpp\r
12 //\r
13 //  Copyright (c) 2002, 2003 Peter Dimov\r
14 //\r
15 // Distributed under the Boost Software License, Version 1.0. (See\r
16 // accompanying file LICENSE_1_0.txt or copy at\r
17 // http://www.boost.org/LICENSE_1_0.txt)\r
18 //\r
19 \r
20 #ifdef BOOST_USE_WINDOWS_H\r
21 #  include <windows.h>\r
22 #endif\r
23 \r
24 namespace boost\r
25 {\r
26 \r
27 namespace detail\r
28 {\r
29 \r
30 #ifndef BOOST_USE_WINDOWS_H\r
31 \r
32 struct critical_section\r
33 {\r
34     struct critical_section_debug * DebugInfo;\r
35     long LockCount;\r
36     long RecursionCount;\r
37     void * OwningThread;\r
38     void * LockSemaphore;\r
39 #if defined(_WIN64)\r
40     unsigned __int64 SpinCount;\r
41 #else\r
42     unsigned long SpinCount;\r
43 #endif\r
44 };\r
45 \r
46 extern "C" __declspec(dllimport) void __stdcall InitializeCriticalSection(critical_section *);\r
47 extern "C" __declspec(dllimport) void __stdcall EnterCriticalSection(critical_section *);\r
48 extern "C" __declspec(dllimport) void __stdcall LeaveCriticalSection(critical_section *);\r
49 extern "C" __declspec(dllimport) void __stdcall DeleteCriticalSection(critical_section *);\r
50 \r
51 #else\r
52 \r
53 typedef ::CRITICAL_SECTION critical_section;\r
54 \r
55 #endif // #ifndef BOOST_USE_WINDOWS_H\r
56 \r
57 class lightweight_mutex\r
58 {\r
59 private:\r
60 \r
61     critical_section cs_;\r
62 \r
63     lightweight_mutex(lightweight_mutex const &);\r
64     lightweight_mutex & operator=(lightweight_mutex const &);\r
65 \r
66 public:\r
67 \r
68     lightweight_mutex()\r
69     {\r
70         InitializeCriticalSection(&cs_);\r
71     }\r
72 \r
73     ~lightweight_mutex()\r
74     {\r
75         DeleteCriticalSection(&cs_);\r
76     }\r
77 \r
78     class scoped_lock;\r
79     friend class scoped_lock;\r
80 \r
81     class scoped_lock\r
82     {\r
83     private:\r
84 \r
85         lightweight_mutex & m_;\r
86 \r
87         scoped_lock(scoped_lock const &);\r
88         scoped_lock & operator=(scoped_lock const &);\r
89 \r
90     public:\r
91 \r
92         explicit scoped_lock(lightweight_mutex & m): m_(m)\r
93         {\r
94             EnterCriticalSection(&m_.cs_);\r
95         }\r
96 \r
97         ~scoped_lock()\r
98         {\r
99             LeaveCriticalSection(&m_.cs_);\r
100         }\r
101     };\r
102 };\r
103 \r
104 } // namespace detail\r
105 \r
106 } // namespace boost\r
107 \r
108 #endif // #ifndef BOOST_DETAIL_LWM_WIN32_CS_HPP_INCLUDED\r