/*
This file is a part of libcds - Concurrent Data Structures library
- (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016
+ (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2017
Source code repo: http://github.com/khizmax/libcds/
Download: http://sourceforge.net/projects/libcds/files/
public:
/// Construct free (unlocked) spin-lock
spin_lock() CDS_NOEXCEPT
+ : m_spin( false )
# ifdef CDS_DEBUG
- :m_dbgOwnerId( OS::c_NullThreadId )
+ , m_dbgOwnerId( OS::c_NullThreadId )
# endif
- {
- m_spin.store( false, atomics::memory_order_relaxed );
- }
+ {}
/// Construct spin-lock in specified state
/**
bool try_lock() CDS_NOEXCEPT
{
bool bCurrent = false;
- m_spin.compare_exchange_strong( bCurrent, true, atomics::memory_order_acquire, atomics::memory_order_relaxed );
+
+ m_spin.compare_exchange_strong( bCurrent, true, atomics::memory_order_acquire, atomics::memory_order_acquire );
CDS_DEBUG_ONLY(
if ( !bCurrent ) {
{
backoff_strategy backoff;
while ( nTryCount-- ) {
- if ( try_lock() ) {
- CDS_TSAN_ANNOTATE_MUTEX_ACQUIRED( &m_spin );
+ if ( try_lock() )
return true;
- }
backoff();
}
return false;
CDS_DEBUG_ONLY( m_dbgOwnerId = OS::c_NullThreadId; )
m_spin.store( false, atomics::memory_order_release );
- CDS_TSAN_ANNOTATE_MUTEX_RELEASED( &m_spin );
}
};
bool try_acquire() CDS_NOEXCEPT
{
integral_type nCurrent = 0;
- return m_spin.compare_exchange_weak( nCurrent, 1, atomics::memory_order_acquire, atomics::memory_order_relaxed );
+ return m_spin.compare_exchange_weak( nCurrent, 1, atomics::memory_order_acquire, atomics::memory_order_acquire );
}
bool try_acquire( unsigned int nTryCount ) CDS_NOEXCEPT_( noexcept( backoff_strategy()()))
backoff_strategy bkoff;
while ( nTryCount-- ) {
- if ( try_acquire() ) {
- CDS_TSAN_ANNOTATE_MUTEX_ACQUIRED( &m_spin );
+ if ( try_acquire() )
return true;
- }
bkoff();
}
return false;
, m_OwnerId( OS::c_NullThreadId )
{}
- /// Construct object for specified state
+ /// Construct object in specified state
explicit reentrant_spin_lock( bool bLocked )
: m_spin(0)
, m_OwnerId( OS::c_NullThreadId )
else {
free();
m_spin.store( 0, atomics::memory_order_release );
- CDS_TSAN_ANNOTATE_MUTEX_RELEASED( &m_spin );
}
return true;
}