Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:51:42

0001 #ifndef BOOST_SMART_PTR_DETAIL_LWM_WIN32_CS_HPP_INCLUDED
0002 #define BOOST_SMART_PTR_DETAIL_LWM_WIN32_CS_HPP_INCLUDED
0003 
0004 // MS compatible compilers support #pragma once
0005 
0006 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
0007 # pragma once
0008 #endif
0009 
0010 //
0011 //  boost/detail/lwm_win32_cs.hpp
0012 //
0013 //  Copyright (c) 2002, 2003 Peter Dimov
0014 //
0015 // Distributed under the Boost Software License, Version 1.0. (See
0016 // accompanying file LICENSE_1_0.txt or copy at
0017 // http://www.boost.org/LICENSE_1_0.txt)
0018 //
0019 
0020 #ifdef BOOST_USE_WINDOWS_H
0021 
0022 #include <windows.h>
0023 
0024 #else
0025 
0026 struct _RTL_CRITICAL_SECTION;
0027 
0028 #endif
0029 
0030 namespace boost
0031 {
0032 
0033 namespace detail
0034 {
0035 
0036 #ifndef BOOST_USE_WINDOWS_H
0037 
0038 struct critical_section
0039 {
0040     struct critical_section_debug * DebugInfo;
0041     long LockCount;
0042     long RecursionCount;
0043     void * OwningThread;
0044     void * LockSemaphore;
0045 #if defined(_WIN64)
0046     unsigned __int64 SpinCount;
0047 #else
0048     unsigned long SpinCount;
0049 #endif
0050 };
0051 
0052 extern "C" __declspec(dllimport) void __stdcall InitializeCriticalSection(::_RTL_CRITICAL_SECTION *);
0053 extern "C" __declspec(dllimport) void __stdcall EnterCriticalSection(::_RTL_CRITICAL_SECTION *);
0054 extern "C" __declspec(dllimport) void __stdcall LeaveCriticalSection(::_RTL_CRITICAL_SECTION *);
0055 extern "C" __declspec(dllimport) void __stdcall DeleteCriticalSection(::_RTL_CRITICAL_SECTION *);
0056 
0057 typedef ::_RTL_CRITICAL_SECTION rtl_critical_section;
0058 
0059 #else // #ifndef BOOST_USE_WINDOWS_H
0060 
0061 typedef ::CRITICAL_SECTION critical_section;
0062 
0063 using ::InitializeCriticalSection;
0064 using ::EnterCriticalSection;
0065 using ::LeaveCriticalSection;
0066 using ::DeleteCriticalSection;
0067 
0068 typedef ::CRITICAL_SECTION rtl_critical_section;
0069 
0070 #endif // #ifndef BOOST_USE_WINDOWS_H
0071 
0072 class lightweight_mutex
0073 {
0074 private:
0075 
0076     critical_section cs_;
0077 
0078     lightweight_mutex(lightweight_mutex const &);
0079     lightweight_mutex & operator=(lightweight_mutex const &);
0080 
0081 public:
0082 
0083     lightweight_mutex()
0084     {
0085         boost::detail::InitializeCriticalSection(reinterpret_cast< rtl_critical_section* >(&cs_));
0086     }
0087 
0088     ~lightweight_mutex()
0089     {
0090         boost::detail::DeleteCriticalSection(reinterpret_cast< rtl_critical_section* >(&cs_));
0091     }
0092 
0093     class scoped_lock;
0094     friend class scoped_lock;
0095 
0096     class scoped_lock
0097     {
0098     private:
0099 
0100         lightweight_mutex & m_;
0101 
0102         scoped_lock(scoped_lock const &);
0103         scoped_lock & operator=(scoped_lock const &);
0104 
0105     public:
0106 
0107         explicit scoped_lock(lightweight_mutex & m): m_(m)
0108         {
0109             boost::detail::EnterCriticalSection(reinterpret_cast< rtl_critical_section* >(&m_.cs_));
0110         }
0111 
0112         ~scoped_lock()
0113         {
0114             boost::detail::LeaveCriticalSection(reinterpret_cast< rtl_critical_section* >(&m_.cs_));
0115         }
0116     };
0117 };
0118 
0119 } // namespace detail
0120 
0121 } // namespace boost
0122 
0123 #endif // #ifndef BOOST_SMART_PTR_DETAIL_LWM_WIN32_CS_HPP_INCLUDED