bool try_lock() CDS_NOEXCEPT
{
bool bCurrent = false;
+
+# ifdef CDS_THREAD_SANITIZER_ENABLED
+ if ( m_spin.compare_exchange_strong( bCurrent, true, atomics::memory_order_acquire, atomics::memory_order_relaxed )) {
+ CDS_TSAN_ANNOTATE_MUTEX_ACQUIRED( &m_spin );
+ }
+# else
m_spin.compare_exchange_strong( bCurrent, true, atomics::memory_order_acquire, atomics::memory_order_relaxed );
+# endif
CDS_DEBUG_ONLY(
if ( !bCurrent ) {
Returns \p true if locking is succeeded
otherwise (if the spin is already locked) returns \p false
*/
- bool try_lock( unsigned int nTryCount ) CDS_NOEXCEPT_( noexcept( backoff_strategy()()) )
+ bool try_lock( unsigned int nTryCount ) CDS_NOEXCEPT_( noexcept( backoff_strategy()()))
{
backoff_strategy backoff;
while ( nTryCount-- ) {
- if ( try_lock())
+ if ( try_lock() )
return true;
backoff();
}
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;
+# ifdef CDS_THREAD_SANITIZER_ENABLED
+ if ( m_spin.compare_exchange_weak( nCurrent, 1, atomics::memory_order_acquire, atomics::memory_order_relaxed )) {
+ CDS_TSAN_ANNOTATE_MUTEX_ACQUIRED( &m_spin );
+ return true;
+ }
+ return false;
+# else
return m_spin.compare_exchange_weak( nCurrent, 1, atomics::memory_order_acquire, atomics::memory_order_relaxed );
+# endif
}
bool try_acquire( unsigned int nTryCount ) CDS_NOEXCEPT_( noexcept( backoff_strategy()()))
backoff_strategy bkoff;
while ( nTryCount-- ) {
- if ( try_acquire())
+ if ( try_acquire() )
return true;
bkoff();
}
/// Unlock the spin-lock. Return \p true if the current thread is owner of spin-lock \p false otherwise
bool unlock() CDS_NOEXCEPT
{
- if ( is_taken( OS::get_current_thread_id()) ) {
+ if ( is_taken( OS::get_current_thread_id())) {
integral_type n = m_spin.load( atomics::memory_order_relaxed );
if ( n > 1 )
m_spin.store( n - 1, atomics::memory_order_relaxed );
else {
free();
m_spin.store( 0, atomics::memory_order_release );
+ CDS_TSAN_ANNOTATE_MUTEX_RELEASED( &m_spin );
}
return true;
}
/// Change the owner of locked spin-lock. May be called by thread that is owner of the spin-lock
bool change_owner( OS::ThreadId newOwnerId ) CDS_NOEXCEPT
{
- if ( is_taken( OS::get_current_thread_id()) ) {
+ if ( is_taken( OS::get_current_thread_id())) {
assert( newOwnerId != OS::c_NullThreadId );
m_OwnerId = newOwnerId;
return true;