lwm_win32_cs.hpp

Go to the documentation of this file.
00001 #ifndef BOOST_DETAIL_LWM_WIN32_CS_HPP_INCLUDED
00002 #define BOOST_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 #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 } // namespace detail
00101 
00102 } // namespace boost
00103 
00104 #endif // #ifndef BOOST_DETAIL_LWM_WIN32_CS_HPP_INCLUDED

Generated on Wed Jan 21 15:32:09 2009 for SystemC by  doxygen 1.5.5