public inbox for
help / color / mirror / Atom feed
From: Jonathan Wakely <>
Subject: [gcc r13-2688] libstdc++: Tweak TSan annotations for std::atomic<shared_ptr<T>>
Date: Thu, 15 Sep 2022 20:05:07 +0000 (GMT)	[thread overview]
Message-ID: <> (raw)

commit r13-2688-gecbdfa8b314e2c17da17511b86371f552bffd441
Author: Jonathan Wakely <>
Date:   Thu Sep 15 16:57:30 2022 +0100

    libstdc++: Tweak TSan annotations for std::atomic<shared_ptr<T>>
    Do not use the __tsan_mutex_not_static flag for annotation functions
    where it's not a valid flag.  Also use the try_lock and try_lock_failed
    flags to more precisely annotate the CAS loop used to acquire a lock.
            * include/bits/shared_ptr_atomic.h (_GLIBCXX_TSAN_MUTEX_PRE_LOCK):
            Replace with ...
            (_GLIBCXX_TSAN_MUTEX_TRY_LOCK): ... this, add try_lock flag.
            (_GLIBCXX_TSAN_MUTEX_TRY_LOCK_FAILED): New macro using
            try_lock_failed flag
            (_GLIBCXX_TSAN_MUTEX_POST_LOCK): Rename to ...
            (_GLIBCXX_TSAN_MUTEX_LOCKED): ... this.
            (_GLIBCXX_TSAN_MUTEX_PRE_UNLOCK): Remove invalid flag.
            (_GLIBCXX_TSAN_MUTEX_POST_UNLOCK): Remove invalid flag.
            (_Sp_atomic::_Atomic_count::lock): Use new macros.

 libstdc++-v3/include/bits/shared_ptr_atomic.h | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/libstdc++-v3/include/bits/shared_ptr_atomic.h b/libstdc++-v3/include/bits/shared_ptr_atomic.h
index 4580807f42c..55d193d4bda 100644
--- a/libstdc++-v3/include/bits/shared_ptr_atomic.h
+++ b/libstdc++-v3/include/bits/shared_ptr_atomic.h
@@ -32,24 +32,26 @@
 #include <bits/atomic_base.h>
+// Annotations for the custom locking in atomic<shared_ptr<T>>.
 #if defined _GLIBCXX_TSAN && __has_include(<sanitizer/tsan_interface.h>)
 #include <sanitizer/tsan_interface.h>
   __tsan_mutex_destroy(X, __tsan_mutex_not_static)
-  __tsan_mutex_pre_lock(X, __tsan_mutex_not_static)
+  __tsan_mutex_pre_lock(X, __tsan_mutex_not_static|__tsan_mutex_try_lock)
+#define _GLIBCXX_TSAN_MUTEX_TRY_LOCK_FAILED(X) __tsan_mutex_post_lock(X, \
+    __tsan_mutex_not_static|__tsan_mutex_try_lock_failed, 0)
   __tsan_mutex_post_lock(X, __tsan_mutex_not_static, 0)
-  __tsan_mutex_pre_unlock(X, __tsan_mutex_not_static)
-  __tsan_mutex_post_unlock(X, __tsan_mutex_not_static)
+#define _GLIBCXX_TSAN_MUTEX_PRE_UNLOCK(X) __tsan_mutex_pre_unlock(X, 0)
+#define _GLIBCXX_TSAN_MUTEX_POST_UNLOCK(X) __tsan_mutex_post_unlock(X, 0)
 #define _GLIBCXX_TSAN_MUTEX_PRE_SIGNAL(X) __tsan_mutex_pre_signal(X, 0)
 #define _GLIBCXX_TSAN_MUTEX_POST_SIGNAL(X) __tsan_mutex_post_signal(X, 0)
 	      __current = _M_val.load(memory_order_relaxed);
 	  while (!_M_val.compare_exchange_strong(__current,
 						 __current | _S_lock_bit,
 #if __cpp_lib_atomic_wait
 	      __current = __current & ~_S_lock_bit;
 	  return reinterpret_cast<pointer>(__current);

                 reply	other threads:[~2022-09-15 20:05 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).