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