Skip to content

Commit

Permalink
absl: fix Mutex TSan annotations
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Abseil Team authored and copybara-github committed Nov 28, 2022
1 parent 9f4bde3 commit bb7be49
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions absl/synchronization/mutex.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

Expand Down

0 comments on commit bb7be49

Please sign in to comment.