1 #ifndef BOOST_DETAIL_SPINLOCK_W32_HPP_INCLUDED
2 #define BOOST_DETAIL_SPINLOCK_W32_HPP_INCLUDED
4 // MS compatible compilers support #pragma once
6 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
11 // Copyright (c) 2008 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/detail/interlocked.hpp>
19 #include <boost/detail/yield_k.hpp>
21 // BOOST_COMPILER_FENCE
23 #if defined(__INTEL_COMPILER)
25 #define BOOST_COMPILER_FENCE __memory_barrier();
27 #elif defined( _MSC_VER ) && _MSC_VER >= 1310
29 extern "C" void _ReadWriteBarrier();
30 #pragma intrinsic( _ReadWriteBarrier )
32 #define BOOST_COMPILER_FENCE _ReadWriteBarrier();
34 #elif defined(__GNUC__)
36 #define BOOST_COMPILER_FENCE __asm__ __volatile__( "" : : : "memory" );
40 #define BOOST_COMPILER_FENCE
62 long r = BOOST_INTERLOCKED_EXCHANGE( &v_, 1 );
71 for( unsigned k = 0; !try_lock(); ++k )
73 boost::detail::yield( k );
80 *const_cast< long volatile* >( &v_ ) = 0;
91 scoped_lock( scoped_lock const & );
92 scoped_lock & operator=( scoped_lock const & );
96 explicit scoped_lock( spinlock & sp ): sp_( sp )
108 } // namespace detail
111 #define BOOST_DETAIL_SPINLOCK_INIT {0}
113 #endif // #ifndef BOOST_DETAIL_SPINLOCK_W32_HPP_INCLUDED