Go to the documentation of this file.00001 #ifndef BOOST_SMART_PTR_DETAIL_SPINLOCK_NT_HPP_INCLUDED
00002 #define BOOST_SMART_PTR_DETAIL_SPINLOCK_NT_HPP_INCLUDED
00003
00004
00005
00006 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
00007 # pragma once
00008 #endif
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <boost/assert.hpp>
00019
00020 namespace boost
00021 {
00022
00023 namespace detail
00024 {
00025
00026 class spinlock
00027 {
00028 public:
00029
00030 bool locked_;
00031
00032 public:
00033
00034 inline bool try_lock()
00035 {
00036 if( locked_ )
00037 {
00038 return false;
00039 }
00040 else
00041 {
00042 locked_ = true;
00043 return true;
00044 }
00045 }
00046
00047 inline void lock()
00048 {
00049 BOOST_ASSERT( !locked_ );
00050 locked_ = true;
00051 }
00052
00053 inline void unlock()
00054 {
00055 BOOST_ASSERT( locked_ );
00056 locked_ = false;
00057 }
00058
00059 public:
00060
00061 class scoped_lock
00062 {
00063 private:
00064
00065 spinlock & sp_;
00066
00067 scoped_lock( scoped_lock const & );
00068 scoped_lock & operator=( scoped_lock const & );
00069
00070 public:
00071
00072 explicit scoped_lock( spinlock & sp ): sp_( sp )
00073 {
00074 sp.lock();
00075 }
00076
00077 ~scoped_lock()
00078 {
00079 sp_.unlock();
00080 }
00081 };
00082 };
00083
00084 }
00085 }
00086
00087 #define BOOST_DETAIL_SPINLOCK_INIT { false }
00088
00089 #endif // #ifndef BOOST_SMART_PTR_DETAIL_SPINLOCK_NT_HPP_INCLUDED