00001 #ifndef BOOST_DETAIL_LWM_WIN32_CS_HPP_INCLUDED
00002 #define BOOST_DETAIL_LWM_WIN32_CS_HPP_INCLUDED
00003
00004
00005
00006 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
00007 # pragma once
00008 #endif
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifdef BOOST_USE_WINDOWS_H
00021 # include <windows.h>
00022 #endif
00023
00024 namespace boost
00025 {
00026
00027 namespace detail
00028 {
00029
00030 #ifndef BOOST_USE_WINDOWS_H
00031
00032 struct CRITICAL_SECTION
00033 {
00034 struct critical_section_debug * DebugInfo;
00035 long LockCount;
00036 long RecursionCount;
00037 void * OwningThread;
00038 void * LockSemaphore;
00039 #if defined(_WIN64)
00040 unsigned __int64 SpinCount;
00041 #else
00042 unsigned long SpinCount;
00043 #endif
00044 };
00045
00046 extern "C" __declspec(dllimport) void __stdcall InitializeCriticalSection(CRITICAL_SECTION *);
00047 extern "C" __declspec(dllimport) void __stdcall EnterCriticalSection(CRITICAL_SECTION *);
00048 extern "C" __declspec(dllimport) void __stdcall LeaveCriticalSection(CRITICAL_SECTION *);
00049 extern "C" __declspec(dllimport) void __stdcall DeleteCriticalSection(CRITICAL_SECTION *);
00050
00051 #endif // #ifndef BOOST_USE_WINDOWS_H
00052
00053 class lightweight_mutex
00054 {
00055 private:
00056
00057 CRITICAL_SECTION cs_;
00058
00059 lightweight_mutex(lightweight_mutex const &);
00060 lightweight_mutex & operator=(lightweight_mutex const &);
00061
00062 public:
00063
00064 lightweight_mutex()
00065 {
00066 InitializeCriticalSection(&cs_);
00067 }
00068
00069 ~lightweight_mutex()
00070 {
00071 DeleteCriticalSection(&cs_);
00072 }
00073
00074 class scoped_lock;
00075 friend class scoped_lock;
00076
00077 class scoped_lock
00078 {
00079 private:
00080
00081 lightweight_mutex & m_;
00082
00083 scoped_lock(scoped_lock const &);
00084 scoped_lock & operator=(scoped_lock const &);
00085
00086 public:
00087
00088 explicit scoped_lock(lightweight_mutex & m): m_(m)
00089 {
00090 EnterCriticalSection(&m_.cs_);
00091 }
00092
00093 ~scoped_lock()
00094 {
00095 LeaveCriticalSection(&m_.cs_);
00096 }
00097 };
00098 };
00099
00100 }
00101
00102 }
00103
00104 #endif // #ifndef BOOST_DETAIL_LWM_WIN32_CS_HPP_INCLUDED