Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect mutex implementation selector when futexes are desired #178

Merged
merged 2 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading