Chris@16: #ifndef BOOST_SMART_PTR_DETAIL_SPINLOCK_NT_HPP_INCLUDED Chris@16: #define BOOST_SMART_PTR_DETAIL_SPINLOCK_NT_HPP_INCLUDED Chris@16: Chris@16: // MS compatible compilers support #pragma once Chris@16: Chris@16: #if defined(_MSC_VER) && (_MSC_VER >= 1020) Chris@16: # pragma once Chris@16: #endif Chris@16: Chris@16: // Chris@16: // Copyright (c) 2008 Peter Dimov Chris@16: // Chris@16: // Distributed under the Boost Software License, Version 1.0. Chris@16: // See accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: // Chris@16: Chris@16: #include Chris@16: Chris@16: namespace boost Chris@16: { Chris@16: Chris@16: namespace detail Chris@16: { Chris@16: Chris@16: class spinlock Chris@16: { Chris@16: public: Chris@16: Chris@16: bool locked_; Chris@16: Chris@16: public: Chris@16: Chris@16: inline bool try_lock() Chris@16: { Chris@16: if( locked_ ) Chris@16: { Chris@16: return false; Chris@16: } Chris@16: else Chris@16: { Chris@16: locked_ = true; Chris@16: return true; Chris@16: } Chris@16: } Chris@16: Chris@16: inline void lock() Chris@16: { Chris@16: BOOST_ASSERT( !locked_ ); Chris@16: locked_ = true; Chris@16: } Chris@16: Chris@16: inline void unlock() Chris@16: { Chris@16: BOOST_ASSERT( locked_ ); Chris@16: locked_ = false; Chris@16: } Chris@16: Chris@16: public: Chris@16: Chris@16: class scoped_lock Chris@16: { Chris@16: private: Chris@16: Chris@16: spinlock & sp_; Chris@16: Chris@16: scoped_lock( scoped_lock const & ); Chris@16: scoped_lock & operator=( scoped_lock const & ); Chris@16: Chris@16: public: Chris@16: Chris@16: explicit scoped_lock( spinlock & sp ): sp_( sp ) Chris@16: { Chris@16: sp.lock(); Chris@16: } Chris@16: Chris@16: ~scoped_lock() Chris@16: { Chris@16: sp_.unlock(); Chris@16: } Chris@16: }; Chris@16: }; Chris@16: Chris@16: } // namespace detail Chris@16: } // namespace boost Chris@16: Chris@16: #define BOOST_DETAIL_SPINLOCK_INIT { false } Chris@16: Chris@16: #endif // #ifndef BOOST_SMART_PTR_DETAIL_SPINLOCK_NT_HPP_INCLUDED