1 #ifndef BOOST_SMART_PTR_DETAIL_SPINLOCK_STD_ATOMIC_HPP_INCLUDED
2 #define BOOST_SMART_PTR_DETAIL_SPINLOCK_STD_ATOMIC_HPP_INCLUDED
4 // MS compatible compilers support #pragma once
6 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
11 // Copyright (c) 2014 Peter Dimov
13 // Distributed under the Boost Software License, Version 1.0.
14 // See accompanying file LICENSE_1_0.txt or copy at
15 // http://www.boost.org/LICENSE_1_0.txt)
18 #include <boost/smart_ptr/detail/yield_k.hpp>
19 #include <boost/config.hpp>
36 bool try_lock() BOOST_NOEXCEPT
38 return !v_.test_and_set( std::memory_order_acquire );
41 void lock() BOOST_NOEXCEPT
43 for( unsigned k = 0; !try_lock(); ++k )
45 boost::detail::yield( k );
49 void unlock() BOOST_NOEXCEPT
51 v_ .clear( std::memory_order_release );
62 scoped_lock( scoped_lock const & );
63 scoped_lock & operator=( scoped_lock const & );
67 explicit scoped_lock( spinlock & sp ) BOOST_NOEXCEPT: sp_( sp )
72 ~scoped_lock() /*BOOST_NOEXCEPT*/
82 #define BOOST_DETAIL_SPINLOCK_INIT { ATOMIC_FLAG_INIT }
84 #endif // #ifndef BOOST_SMART_PTR_DETAIL_SPINLOCK_STD_ATOMIC_HPP_INCLUDED