00001 #ifndef BOOST_DETAIL_LWM_WIN32_HPP_INCLUDED
00002 #define BOOST_DETAIL_LWM_WIN32_HPP_INCLUDED
00003
00004 #if _MSC_VER >= 1020
00005 #pragma once
00006 #endif
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <sysc/packages/boost/detail/winapi.hpp>
00020
00021 #ifdef __BORLANDC__
00022 # pragma warn -8027 // Functions containing while are not expanded inline
00023 #endif
00024
00025 namespace boost
00026 {
00027
00028 namespace detail
00029 {
00030
00031 class lightweight_mutex
00032 {
00033 private:
00034
00035 long l_;
00036
00037 lightweight_mutex(lightweight_mutex const &);
00038 lightweight_mutex & operator=(lightweight_mutex const &);
00039
00040 public:
00041
00042 lightweight_mutex(): l_(0)
00043 {
00044 }
00045
00046 class scoped_lock;
00047 friend class scoped_lock;
00048
00049 class scoped_lock
00050 {
00051 private:
00052
00053 lightweight_mutex & m_;
00054
00055 scoped_lock(scoped_lock const &);
00056 scoped_lock & operator=(scoped_lock const &);
00057
00058 public:
00059
00060 explicit scoped_lock(lightweight_mutex & m): m_(m)
00061 {
00062 while( winapi::InterlockedExchange(&m_.l_, 1) )
00063 {
00064
00065
00066
00067
00068
00069 winapi::Sleep(1);
00070 }
00071 }
00072
00073 ~scoped_lock()
00074 {
00075 winapi::InterlockedExchange(&m_.l_, 0);
00076
00077
00078
00079
00080
00081
00082 }
00083 };
00084 };
00085
00086 }
00087
00088 }
00089
00090 #ifdef __BORLANDC__
00091 # pragma warn .8027 // Functions containing while are not expanded inline
00092 #endif
00093
00094 #endif // #ifndef BOOST_DETAIL_LWM_WIN32_HPP_INCLUDED