]> git.lyx.org Git - lyx.git/blob - boost/boost/detail/lwm_win32_cs.hpp
Boost 1.31.0
[lyx.git] / boost / boost / detail / lwm_win32_cs.hpp
1 #ifndef BOOST_DETAIL_LWM_WIN32_CS_HPP_INCLUDED
2 #define BOOST_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 //  Permission to copy, use, modify, sell and distribute this software
16 //  is granted provided this copyright notice appears in all copies.
17 //  This software is provided "as is" without express or implied
18 //  warranty, and with no claim as to its suitability for any purpose.
19 //
20
21 #ifdef BOOST_USE_WINDOWS_H
22 #  include <windows.h>
23 #endif
24
25 namespace boost
26 {
27
28 namespace detail
29 {
30
31 #ifndef BOOST_USE_WINDOWS_H
32
33 struct CRITICAL_SECTION
34 {
35     struct critical_section_debug * DebugInfo;
36     long LockCount;
37     long RecursionCount;
38     void * OwningThread;
39     void * LockSemaphore;
40 #if defined(_WIN64)
41     unsigned __int64 SpinCount;
42 #else
43     unsigned long SpinCount;
44 #endif
45 };
46
47 extern "C" __declspec(dllimport) void __stdcall InitializeCriticalSection(CRITICAL_SECTION *);
48 extern "C" __declspec(dllimport) void __stdcall EnterCriticalSection(CRITICAL_SECTION *);
49 extern "C" __declspec(dllimport) void __stdcall LeaveCriticalSection(CRITICAL_SECTION *);
50 extern "C" __declspec(dllimport) void __stdcall DeleteCriticalSection(CRITICAL_SECTION *);
51
52 #endif // #ifndef BOOST_USE_WINDOWS_H
53
54 class lightweight_mutex
55 {
56 private:
57
58     CRITICAL_SECTION cs_;
59
60     lightweight_mutex(lightweight_mutex const &);
61     lightweight_mutex & operator=(lightweight_mutex const &);
62
63 public:
64
65     lightweight_mutex()
66     {
67         InitializeCriticalSection(&cs_);
68     }
69
70     ~lightweight_mutex()
71     {
72         DeleteCriticalSection(&cs_);
73     }
74
75     class scoped_lock;
76     friend class scoped_lock;
77
78     class scoped_lock
79     {
80     private:
81
82         lightweight_mutex & m_;
83
84         scoped_lock(scoped_lock const &);
85         scoped_lock & operator=(scoped_lock const &);
86
87     public:
88
89         explicit scoped_lock(lightweight_mutex & m): m_(m)
90         {
91             EnterCriticalSection(&m_.cs_);
92         }
93
94         ~scoped_lock()
95         {
96             LeaveCriticalSection(&m_.cs_);
97         }
98     };
99 };
100
101 } // namespace detail
102
103 } // namespace boost
104
105 #endif // #ifndef BOOST_DETAIL_LWM_WIN32_CS_HPP_INCLUDED