From bb7be494b385975ebdeaac3a8ee10894405641e4 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Mon, 28 Nov 2022 03:22:59 -0800 Subject: [PATCH] absl: fix Mutex TSan annotations TSan misses synchronization around passing PerThreadSynch between threads since it happens inside of the Mutex code (which me mostly ignore), so we need to ignore all accesses to the object. PiperOrigin-RevId: 491297912 Change-Id: I13ea2015dee5c1a3fc4315c85112902ccffccc45 --- absl/synchronization/mutex.cc | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/absl/synchronization/mutex.cc b/absl/synchronization/mutex.cc index dd771421f80..ddd8fb8d259 100644 --- a/absl/synchronization/mutex.cc +++ b/absl/synchronization/mutex.cc @@ -591,10 +591,15 @@ static SynchLocksHeld *Synch_GetAllLocks() { void Mutex::IncrementSynchSem(Mutex *mu, PerThreadSynch *w) { if (mu) { ABSL_TSAN_MUTEX_PRE_DIVERT(mu, 0); - } - PerThreadSem::Post(w->thread_identity()); - if (mu) { + // We miss synchronization around passing PerThreadSynch between threads + // since it happens inside of the Mutex code, so we need to ignore all + // accesses to the object. + ABSL_ANNOTATE_IGNORE_READS_AND_WRITES_BEGIN(); + PerThreadSem::Post(w->thread_identity()); + ABSL_ANNOTATE_IGNORE_READS_AND_WRITES_END(); ABSL_TSAN_MUTEX_POST_DIVERT(mu, 0); + } else { + PerThreadSem::Post(w->thread_identity()); } }