File indexing completed on 2025-01-18 09:51:40
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef BOOST_SIGNALS2_LWM_WIN32_CS_HPP
0013 #define BOOST_SIGNALS2_LWM_WIN32_CS_HPP
0014
0015
0016
0017 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
0018 # pragma once
0019 #endif
0020
0021 #include <boost/assert.hpp>
0022
0023 #ifdef BOOST_USE_WINDOWS_H
0024
0025 #include <windows.h>
0026
0027 #else
0028
0029 struct _RTL_CRITICAL_SECTION;
0030
0031 #endif
0032
0033 namespace boost
0034 {
0035
0036 namespace signals2
0037 {
0038
0039 namespace detail
0040 {
0041
0042 #ifndef BOOST_USE_WINDOWS_H
0043
0044 struct critical_section
0045 {
0046 struct critical_section_debug * DebugInfo;
0047 long LockCount;
0048 long RecursionCount;
0049 void * OwningThread;
0050 void * LockSemaphore;
0051 #if defined(_WIN64)
0052 unsigned __int64 SpinCount;
0053 #else
0054 unsigned long SpinCount;
0055 #endif
0056 };
0057
0058 extern "C" __declspec(dllimport) void __stdcall InitializeCriticalSection(::_RTL_CRITICAL_SECTION *);
0059 extern "C" __declspec(dllimport) void __stdcall EnterCriticalSection(::_RTL_CRITICAL_SECTION *);
0060 extern "C" __declspec(dllimport) int __stdcall TryEnterCriticalSection(::_RTL_CRITICAL_SECTION *);
0061 extern "C" __declspec(dllimport) void __stdcall LeaveCriticalSection(::_RTL_CRITICAL_SECTION *);
0062 extern "C" __declspec(dllimport) void __stdcall DeleteCriticalSection(::_RTL_CRITICAL_SECTION *);
0063
0064 typedef ::_RTL_CRITICAL_SECTION rtl_critical_section;
0065
0066 #else
0067
0068 typedef ::CRITICAL_SECTION critical_section;
0069
0070 using ::InitializeCriticalSection;
0071 using ::EnterCriticalSection;
0072 using ::TryEnterCriticalSection;
0073 using ::LeaveCriticalSection;
0074 using ::DeleteCriticalSection;
0075
0076 typedef ::CRITICAL_SECTION rtl_critical_section;
0077
0078 #endif
0079
0080 }
0081
0082 class mutex
0083 {
0084 private:
0085
0086 boost::signals2::detail::critical_section cs_;
0087
0088 mutex(mutex const &);
0089 mutex & operator=(mutex const &);
0090
0091 public:
0092
0093 mutex()
0094 {
0095 boost::signals2::detail::InitializeCriticalSection(reinterpret_cast< boost::signals2::detail::rtl_critical_section* >(&cs_));
0096 }
0097
0098 ~mutex()
0099 {
0100 boost::signals2::detail::DeleteCriticalSection(reinterpret_cast< boost::signals2::detail::rtl_critical_section* >(&cs_));
0101 }
0102
0103 void lock()
0104 {
0105 boost::signals2::detail::EnterCriticalSection(reinterpret_cast< boost::signals2::detail::rtl_critical_section* >(&cs_));
0106 }
0107
0108 #if (defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0400))
0109 bool try_lock()
0110 {
0111 return boost::signals2::detail::TryEnterCriticalSection(reinterpret_cast< boost::signals2::detail::rtl_critical_section* >(&cs_)) != 0;
0112 }
0113 #else
0114 bool try_lock()
0115 {
0116 BOOST_ASSERT(false);
0117 return false;
0118 }
0119 #endif
0120 void unlock()
0121 {
0122 boost::signals2::detail::LeaveCriticalSection(reinterpret_cast< boost::signals2::detail::rtl_critical_section* >(&cs_));
0123 }
0124 };
0125
0126 }
0127
0128 }
0129
0130 #endif