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 22 #include <windows.h> 23 24 #else 25 26 struct _RTL_CRITICAL_SECTION; 27 28 #endif 29 30 namespace boost 31 { 32 33 namespace detail 34 { 35 36 #ifndef BOOST_USE_WINDOWS_H 37 38 struct critical_section 39 { 40 struct critical_section_debug * DebugInfo; 41 long LockCount; 42 long RecursionCount; 43 void * OwningThread; 44 void * LockSemaphore; 45 #if defined(_WIN64) 46 unsigned __int64 SpinCount; 47 #else 48 unsigned long SpinCount; 49 #endif 50 }; 51 52 extern "C" __declspec(dllimport) void __stdcall InitializeCriticalSection(::_RTL_CRITICAL_SECTION *); 53 extern "C" __declspec(dllimport) void __stdcall EnterCriticalSection(::_RTL_CRITICAL_SECTION *); 54 extern "C" __declspec(dllimport) void __stdcall LeaveCriticalSection(::_RTL_CRITICAL_SECTION *); 55 extern "C" __declspec(dllimport) void __stdcall DeleteCriticalSection(::_RTL_CRITICAL_SECTION *); 56 57 typedef ::_RTL_CRITICAL_SECTION rtl_critical_section; 58 59 #else // #ifndef BOOST_USE_WINDOWS_H 60 61 typedef ::CRITICAL_SECTION critical_section; 62 63 using ::InitializeCriticalSection; 64 using ::EnterCriticalSection; 65 using ::LeaveCriticalSection; 66 using ::DeleteCriticalSection; 67 68 typedef ::CRITICAL_SECTION rtl_critical_section; 69 70 #endif // #ifndef BOOST_USE_WINDOWS_H 71 72 class lightweight_mutex 73 { 74 private: 75 76 critical_section cs_; 77 78 lightweight_mutex(lightweight_mutex const &); 79 lightweight_mutex & operator=(lightweight_mutex const &); 80 81 public: 82 lightweight_mutex()83 lightweight_mutex() 84 { 85 boost::detail::InitializeCriticalSection(reinterpret_cast< rtl_critical_section* >(&cs_)); 86 } 87 ~lightweight_mutex()88 ~lightweight_mutex() 89 { 90 boost::detail::DeleteCriticalSection(reinterpret_cast< rtl_critical_section* >(&cs_)); 91 } 92 93 class scoped_lock; 94 friend class scoped_lock; 95 96 class scoped_lock 97 { 98 private: 99 100 lightweight_mutex & m_; 101 102 scoped_lock(scoped_lock const &); 103 scoped_lock & operator=(scoped_lock const &); 104 105 public: 106 scoped_lock(lightweight_mutex & m)107 explicit scoped_lock(lightweight_mutex & m): m_(m) 108 { 109 boost::detail::EnterCriticalSection(reinterpret_cast< rtl_critical_section* >(&m_.cs_)); 110 } 111 ~scoped_lock()112 ~scoped_lock() 113 { 114 boost::detail::LeaveCriticalSection(reinterpret_cast< rtl_critical_section* >(&m_.cs_)); 115 } 116 }; 117 }; 118 119 } // namespace detail 120 121 } // namespace boost 122 123 #endif // #ifndef BOOST_SMART_PTR_DETAIL_LWM_WIN32_CS_HPP_INCLUDED 124