Skip to content

Commit

Permalink
Fix incorrect mutex implementation selector when futexes are desired
Browse files Browse the repository at this point in the history
  • Loading branch information
mattrm456 authored Jun 21, 2024
1 parent a624d18 commit e1d25f0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions groups/ntc/ntccfg/ntccfg_mutex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace ntccfg {
#if NTCCFG_FUTEX_ENABLED

// Some versions of GCC issue a spurious warning that the 'current' paramter
// is set but not used when 'Mutex::compareAndSwap' is called.
// is set but not used when 'Futex::compareAndSwap' is called.
#if defined(BSLS_PLATFORM_CMP_GNU)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-but-set-parameter"
Expand All @@ -51,7 +51,7 @@ __attribute__((noinline)) void Futex::wake()
syscall(SYS_futex, (int*)(&d_value), FUTEX_WAKE, 1, 0, 0, 0);
}

__attribute__((noinline)) void Mutex::lockContention(int c)
__attribute__((noinline)) void Futex::lockContention(int c)
{
do {
if (c == 2 || compareAndSwap(&d_value, 1, 2) != 0) {
Expand Down
14 changes: 7 additions & 7 deletions groups/ntc/ntccfg/ntccfg_mutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace ntccfg {
#if NTCCFG_FUTEX_ENABLED

// Some versions of GCC issue a spurious warning that the 'current' paramter
// is set but not used when 'Mutex::compareAndSwap' is called.
// is set but not used when 'Futex::compareAndSwap' is called.
#if defined(BSLS_PLATFORM_CMP_GNU)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-but-set-parameter"
Expand Down Expand Up @@ -99,7 +99,7 @@ class __attribute__((__aligned__(sizeof(int)))) Futex
};

NTCCFG_INLINE
int Mutex::compareAndSwap(int* current, int expected, int desired)
int Futex::compareAndSwap(int* current, int expected, int desired)
{
int* ep = &expected;
int* dp = &desired;
Expand All @@ -115,18 +115,18 @@ int Mutex::compareAndSwap(int* current, int expected, int desired)
}

NTCCFG_INLINE
Mutex::Mutex()
Futex::Futex()
{
__atomic_store_n(&d_value, 0, __ATOMIC_RELAXED);
}

NTCCFG_INLINE
Mutex::~Mutex()
Futex::~Futex()
{
}

NTCCFG_INLINE
void Mutex::lock()
void Futex::lock()
{
int previous = compareAndSwap(&d_value, 0, 1);
if (previous != 0) {
Expand All @@ -135,7 +135,7 @@ void Mutex::lock()
}

NTCCFG_INLINE
void Mutex::unlock()
void Futex::unlock()
{
int previous = __atomic_fetch_sub(&d_value, 1, __ATOMIC_SEQ_CST);
if (previous != 1) {
Expand Down Expand Up @@ -345,7 +345,7 @@ typedef bslmt::LockGuard<ntccfg::SpinLock> LockGuard;
/// @ingroup module_ntccfg
typedef bslmt::UnLockGuard<ntccfg::SpinLock> UnLockGuard;

#elif NTCCFG_MUTEX_IMPL == NTCCFG_MUTEX_IMPL_BSLMT_FUTEX
#elif NTCCFG_MUTEX_IMPL == NTCCFG_MUTEX_IMPL_FUTEX

/// @internal @brief
/// Provide a synchronization primitive for mutually-exclusive access.
Expand Down

0 comments on commit e1d25f0

Please sign in to comment.