1 #ifndef BOOST_SMART_PTR_DETAIL_SPINLOCK_W32_HPP_INCLUDED
\r
2 #define BOOST_SMART_PTR_DETAIL_SPINLOCK_W32_HPP_INCLUDED
\r
4 // MS compatible compilers support #pragma once
\r
6 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
\r
11 // Copyright (c) 2008 Peter Dimov
\r
13 // Distributed under the Boost Software License, Version 1.0.
\r
14 // See accompanying file LICENSE_1_0.txt or copy at
\r
15 // http://www.boost.org/LICENSE_1_0.txt)
\r
18 #include <boost/detail/interlocked.hpp>
\r
19 #include <boost/smart_ptr/detail/yield_k.hpp>
\r
21 // BOOST_COMPILER_FENCE
\r
23 #if defined(__INTEL_COMPILER)
\r
25 #define BOOST_COMPILER_FENCE __memory_barrier();
\r
27 #elif defined( _MSC_VER ) && _MSC_VER >= 1310
\r
29 extern "C" void _ReadWriteBarrier();
\r
30 #pragma intrinsic( _ReadWriteBarrier )
\r
32 #define BOOST_COMPILER_FENCE _ReadWriteBarrier();
\r
34 #elif defined(__GNUC__)
\r
36 #define BOOST_COMPILER_FENCE __asm__ __volatile__( "" : : : "memory" );
\r
40 #define BOOST_COMPILER_FENCE
\r
62 long r = BOOST_INTERLOCKED_EXCHANGE( &v_, 1 );
\r
64 BOOST_COMPILER_FENCE
\r
71 for( unsigned k = 0; !try_lock(); ++k )
\r
73 boost::detail::yield( k );
\r
79 BOOST_COMPILER_FENCE
\r
80 *const_cast< long volatile* >( &v_ ) = 0;
\r
91 scoped_lock( scoped_lock const & );
\r
92 scoped_lock & operator=( scoped_lock const & );
\r
96 explicit scoped_lock( spinlock & sp ): sp_( sp )
\r
108 } // namespace detail
\r
109 } // namespace boost
\r
111 #define BOOST_DETAIL_SPINLOCK_INIT {0}
\r
113 #endif // #ifndef BOOST_SMART_PTR_DETAIL_SPINLOCK_W32_HPP_INCLUDED
\r