From 59c53435bf0b3e4107cd8e30f6784be2f8d69fa4 Mon Sep 17 00:00:00 2001 From: Peter Andreas Entschev Date: Sat, 16 Mar 2024 01:49:20 -0700 Subject: [PATCH] Drop workaround for `glibc<2.25` Due to a `glibc` bug in versions prior to 2.25, https://github.com/rapidsai/ucxx/pull/93 implemented a workaround to the use of `std::condition_variable`s with a spinlock. Now that RAPIDS is dropping support for CentOS 7, the workaround can also be removed. --- cpp/src/utils/callback_notifier.cpp | 61 +++++++---------------------- 1 file changed, 14 insertions(+), 47 deletions(-) diff --git a/cpp/src/utils/callback_notifier.cpp b/cpp/src/utils/callback_notifier.cpp index 2d5812f9..1e84d46e 100644 --- a/cpp/src/utils/callback_notifier.cpp +++ b/cpp/src/utils/callback_notifier.cpp @@ -5,68 +5,35 @@ #include #include -#ifdef __GLIBC__ -#include -#include -#endif - #include #include namespace ucxx { namespace utils { -#ifdef __GLIBC__ -static const bool _useSpinlock = []() { - auto const libcVersion = std::string{gnu_get_libc_version()}; - auto const dot = libcVersion.find("."); - if (dot == std::string::npos) { - return false; - } else { - // See https://sourceware.org/bugzilla/show_bug.cgi?id=13165 - auto const glibcMajor = std::stoi(libcVersion.substr(0, dot).data()); - auto const glibcMinor = std::stoi(libcVersion.substr(dot + 1).data()); - auto const use = glibcMajor < 2 || (glibcMajor == 2 && glibcMinor < 25); - ucxx_debug("glibc version %s detected, spinlock use is %d", libcVersion.c_str(), use); - return use; - } -}(); -#else -static constexpr bool _useSpinlock = false; -#endif - void CallbackNotifier::set() { - if (_useSpinlock) { - _flag.store(true, std::memory_order_release); - } else { - { - std::lock_guard lock(_mutex); - // This can be relaxed because the mutex is providing - // ordering. - _flag.store(true, std::memory_order_relaxed); - } - _conditionVariable.notify_one(); + { + std::lock_guard lock(_mutex); + // This can be relaxed because the mutex is providing + // ordering. + _flag.store(true, std::memory_order_relaxed); } + _conditionVariable.notify_one(); } bool CallbackNotifier::wait(uint64_t period) { - if (_useSpinlock) { - while (!_flag.load(std::memory_order_acquire)) {} + std::unique_lock lock(_mutex); + // Likewise here, the mutex provides ordering. + if (period > 0) { + return _conditionVariable.wait_for(lock, + std::chrono::duration(period), + [this]() { return _flag.load(std::memory_order_relaxed); }); } else { - std::unique_lock lock(_mutex); - // Likewise here, the mutex provides ordering. - if (period > 0) { - return _conditionVariable.wait_for( - lock, std::chrono::duration(period), [this]() { - return _flag.load(std::memory_order_relaxed); - }); - } else { - _conditionVariable.wait(lock, [this]() { return _flag.load(std::memory_order_relaxed); }); - } + _conditionVariable.wait(lock, [this]() { return _flag.load(std::memory_order_relaxed); }); + return true; } - return true; } } // namespace utils