aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2025-08-19 18:02:53 +0100
committerJonathan Wakely <redi@gcc.gnu.org>2025-08-21 13:26:10 +0100
commitd1dec304453fa4874d16daaa15e6f477435edda4 (patch)
tree74a09c88f36481ad54d221ab65949bfdaf7fed66
parent3182e95eda4a1d612b910b3248c997c8acc7add3 (diff)
downloadgcc-d1dec304453fa4874d16daaa15e6f477435edda4.zip
gcc-d1dec304453fa4874d16daaa15e6f477435edda4.tar.gz
gcc-d1dec304453fa4874d16daaa15e6f477435edda4.tar.bz2
libstdc++: Check _GLIBCXX_USE_PTHREAD_MUTEX_CLOCKLOCK with #if [PR121496]
The change in r14-905-g3b7cb33033fbe6 to disable the use of pthread_mutex_clocklock when TSan is active assumed that the _GLIBCXX_USE_PTHREAD_MUTEX_CLOCKLOCK macro was always checked with #if rather than #ifdef, which was not true. This makes the checks use #if consistently. libstdc++-v3/ChangeLog: PR libstdc++/121496 * include/std/mutex (__timed_mutex_impl::_M_try_wait_until): Change preprocessor condition to use #if instead of #ifdef. (recursive_timed_mutex::_M_clocklock): Likewise. * testsuite/30_threads/timed_mutex/121496.cc: New test. Reviewed-by: Tomasz KamiƄski <tkaminsk@redhat.com>
-rw-r--r--libstdc++-v3/include/std/mutex4
-rw-r--r--libstdc++-v3/testsuite/30_threads/timed_mutex/121496.cc14
2 files changed, 16 insertions, 2 deletions
diff --git a/libstdc++-v3/include/std/mutex b/libstdc++-v3/include/std/mutex
index e575a81..631c380 100644
--- a/libstdc++-v3/include/std/mutex
+++ b/libstdc++-v3/include/std/mutex
@@ -190,7 +190,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return static_cast<_Derived*>(this)->_M_timedlock(__ts);
}
-#ifdef _GLIBCXX_USE_PTHREAD_MUTEX_CLOCKLOCK
+#if _GLIBCXX_USE_PTHREAD_MUTEX_CLOCKLOCK
template<typename _Duration>
bool
_M_try_lock_until(const chrono::time_point<chrono::steady_clock,
@@ -377,7 +377,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_M_timedlock(const __gthread_time_t& __ts)
{ return !__gthread_recursive_mutex_timedlock(&_M_mutex, &__ts); }
-#ifdef _GLIBCXX_USE_PTHREAD_MUTEX_CLOCKLOCK
+#if _GLIBCXX_USE_PTHREAD_MUTEX_CLOCKLOCK
bool
_M_clocklock(clockid_t __clockid, const __gthread_time_t& __ts)
{ return !pthread_mutex_clocklock(&_M_mutex, __clockid, &__ts); }
diff --git a/libstdc++-v3/testsuite/30_threads/timed_mutex/121496.cc b/libstdc++-v3/testsuite/30_threads/timed_mutex/121496.cc
new file mode 100644
index 0000000..d919704
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/timed_mutex/121496.cc
@@ -0,0 +1,14 @@
+// { dg-do compile { target { { i?86-*-linux* x86_64-*-linux* } && lp64 } } }
+// { dg-require-effective-target c++11 }
+// { dg-options "-fsanitize=thread" }
+
+// PR libstdc++/121496 no member named '_M_clocklock' with -fsanitize=thread
+
+#include <mutex>
+#include <chrono>
+
+void
+test_pr121496(std::timed_mutex& m)
+{
+ (void) m.try_lock_until(std::chrono::steady_clock::time_point{});
+}