lwm_win32_cs.hpp
Go to the documentation of this file.
00001 #ifndef BOOST_SMART_PTR_DETAIL_LWM_WIN32_CS_HPP_INCLUDED
00002 #define BOOST_SMART_PTR_DETAIL_LWM_WIN32_CS_HPP_INCLUDED
00003 
00004 // MS compatible compilers support #pragma once
00005 
00006 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
00007 # pragma once
00008 #endif
00009 
00010 //
00011 //  boost/detail/lwm_win32_cs.hpp
00012 //
00013 //  Copyright (c) 2002, 2003 Peter Dimov
00014 //
00015 // Distributed under the Boost Software License, Version 1.0. (See
00016 // accompanying file LICENSE_1_0.txt or copy at
00017 // http://www.boost.org/LICENSE_1_0.txt)
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 #else
00052 
00053 typedef ::CRITICAL_SECTION critical_section;
00054 
00055 #endif // #ifndef BOOST_USE_WINDOWS_H
00056 
00057 class lightweight_mutex
00058 {
00059 private:
00060 
00061     critical_section cs_;
00062 
00063     lightweight_mutex(lightweight_mutex const &);
00064     lightweight_mutex & operator=(lightweight_mutex const &);
00065 
00066 public:
00067 
00068     lightweight_mutex()
00069     {
00070         InitializeCriticalSection(&cs_);
00071     }
00072 
00073     ~lightweight_mutex()
00074     {
00075         DeleteCriticalSection(&cs_);
00076     }
00077 
00078     class scoped_lock;
00079     friend class scoped_lock;
00080 
00081     class scoped_lock
00082     {
00083     private:
00084 
00085         lightweight_mutex & m_;
00086 
00087         scoped_lock(scoped_lock const &);
00088         scoped_lock & operator=(scoped_lock const &);
00089 
00090     public:
00091 
00092         explicit scoped_lock(lightweight_mutex & m): m_(m)
00093         {
00094             EnterCriticalSection(&m_.cs_);
00095         }
00096 
00097         ~scoped_lock()
00098         {
00099             LeaveCriticalSection(&m_.cs_);
00100         }
00101     };
00102 };
00103 
00104 } // namespace detail
00105 
00106 } // namespace boost
00107 
00108 #endif // #ifndef BOOST_SMART_PTR_DETAIL_LWM_WIN32_CS_HPP_INCLUDED


appl
Author(s): petercai
autogenerated on Tue Jan 7 2014 11:02:29