BOOST_COMPILER_FENCE factored out.

[SVN r44058]
This commit is contained in:
Peter Dimov
2008-04-05 16:32:49 +00:00
parent 373c52efa3
commit 6b25c57712

View File

@@ -18,11 +18,31 @@
#include <boost/detail/interlocked.hpp> #include <boost/detail/interlocked.hpp>
#include <boost/detail/yield_k.hpp> #include <boost/detail/yield_k.hpp>
#if defined( _MSC_VER ) && _MSC_VER >= 1310 // BOOST_COMPILER_FENCE
extern "C" void _ReadWriteBarrier();
# pragma intrinsic( _ReadWriteBarrier ) #if defined(__INTEL_COMPILER)
#define BOOST_COMPILER_FENCE __memory_barrier();
#elif defined( _MSC_VER ) && _MSC_VER >= 1310
extern "C" void _ReadWriteBarrier();
#pragma intrinsic( _ReadWriteBarrier )
#define BOOST_COMPILER_FENCE _ReadWriteBarrier();
#elif defined(__GNUC__)
#define BOOST_COMPILER_FENCE __asm__ __volatile__( "" ::: "memory" );
#else
#define BOOST_COMPILER_FENCE
#endif #endif
//
namespace boost namespace boost
{ {
@@ -41,9 +61,7 @@ public:
{ {
long r = BOOST_INTERLOCKED_EXCHANGE( &v_, 1 ); long r = BOOST_INTERLOCKED_EXCHANGE( &v_, 1 );
#if defined( _MSC_VER ) && _MSC_VER >= 1310 BOOST_COMPILER_FENCE
_ReadWriteBarrier();
#endif
return r == 0; return r == 0;
} }
@@ -58,10 +76,7 @@ public:
void unlock() void unlock()
{ {
#if defined( _MSC_VER ) && _MSC_VER >= 1310 BOOST_COMPILER_FENCE
_ReadWriteBarrier();
#endif
*const_cast< long volatile* >( &v_ ) = 0; *const_cast< long volatile* >( &v_ ) = 0;
} }