]> git.donarmstrong.com Git - rsem.git/blob - boost/smart_ptr/detail/lwm_win32_cs.hpp
RSEM Source Codes
[rsem.git] / 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 //
15 // Distributed under the Boost Software License, Version 1.0. (See
16 // accompanying file LICENSE_1_0.txt or copy at
17 // http://www.boost.org/LICENSE_1_0.txt)
18 //
19
20 #ifdef BOOST_USE_WINDOWS_H
21 #  include <windows.h>
22 #endif
23
24 namespace boost
25 {
26
27 namespace detail
28 {
29
30 #ifndef BOOST_USE_WINDOWS_H
31
32 struct critical_section
33 {
34     struct critical_section_debug * DebugInfo;
35     long LockCount;
36     long RecursionCount;
37     void * OwningThread;
38     void * LockSemaphore;
39 #if defined(_WIN64)
40     unsigned __int64 SpinCount;
41 #else
42     unsigned long SpinCount;
43 #endif
44 };
45
46 extern "C" __declspec(dllimport) void __stdcall InitializeCriticalSection(critical_section *);
47 extern "C" __declspec(dllimport) void __stdcall EnterCriticalSection(critical_section *);
48 extern "C" __declspec(dllimport) void __stdcall LeaveCriticalSection(critical_section *);
49 extern "C" __declspec(dllimport) void __stdcall DeleteCriticalSection(critical_section *);
50
51 #else
52
53 typedef ::CRITICAL_SECTION critical_section;
54
55 #endif // #ifndef BOOST_USE_WINDOWS_H
56
57 class lightweight_mutex
58 {
59 private:
60
61     critical_section cs_;
62
63     lightweight_mutex(lightweight_mutex const &);
64     lightweight_mutex & operator=(lightweight_mutex const &);
65
66 public:
67
68     lightweight_mutex()
69     {
70         InitializeCriticalSection(&cs_);
71     }
72
73     ~lightweight_mutex()
74     {
75         DeleteCriticalSection(&cs_);
76     }
77
78     class scoped_lock;
79     friend class scoped_lock;
80
81     class scoped_lock
82     {
83     private:
84
85         lightweight_mutex & m_;
86
87         scoped_lock(scoped_lock const &);
88         scoped_lock & operator=(scoped_lock const &);
89
90     public:
91
92         explicit scoped_lock(lightweight_mutex & m): m_(m)
93         {
94             EnterCriticalSection(&m_.cs_);
95         }
96
97         ~scoped_lock()
98         {
99             LeaveCriticalSection(&m_.cs_);
100         }
101     };
102 };
103
104 } // namespace detail
105
106 } // namespace boost
107
108 #endif // #ifndef BOOST_SMART_PTR_DETAIL_LWM_WIN32_CS_HPP_INCLUDED