File indexing completed on 2025-01-18 09:51:43
0001 #ifndef BOOST_SMART_PTR_DETAIL_SPINLOCK_NT_HPP_INCLUDED
0002 #define BOOST_SMART_PTR_DETAIL_SPINLOCK_NT_HPP_INCLUDED
0003
0004
0005
0006 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
0007 # pragma once
0008 #endif
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 #include <boost/assert.hpp>
0019
0020 #if defined(BOOST_SP_REPORT_IMPLEMENTATION)
0021
0022 #include <boost/config/pragma_message.hpp>
0023 BOOST_PRAGMA_MESSAGE("Using single-threaded spinlock emulation")
0024
0025 #endif
0026
0027 namespace boost
0028 {
0029
0030 namespace detail
0031 {
0032
0033 class spinlock
0034 {
0035 public:
0036
0037 bool locked_;
0038
0039 public:
0040
0041 inline bool try_lock()
0042 {
0043 if( locked_ )
0044 {
0045 return false;
0046 }
0047 else
0048 {
0049 locked_ = true;
0050 return true;
0051 }
0052 }
0053
0054 inline void lock()
0055 {
0056 BOOST_ASSERT( !locked_ );
0057 locked_ = true;
0058 }
0059
0060 inline void unlock()
0061 {
0062 BOOST_ASSERT( locked_ );
0063 locked_ = false;
0064 }
0065
0066 public:
0067
0068 class scoped_lock
0069 {
0070 private:
0071
0072 spinlock & sp_;
0073
0074 scoped_lock( scoped_lock const & );
0075 scoped_lock & operator=( scoped_lock const & );
0076
0077 public:
0078
0079 explicit scoped_lock( spinlock & sp ): sp_( sp )
0080 {
0081 sp.lock();
0082 }
0083
0084 ~scoped_lock()
0085 {
0086 sp_.unlock();
0087 }
0088 };
0089 };
0090
0091 }
0092 }
0093
0094 #define BOOST_DETAIL_SPINLOCK_INIT { false }
0095
0096 #endif