Skip to content
This repository was archived by the owner on May 21, 2019. It is now read-only.

Commit fc4a9bf

Browse files
committed
Remove strict tid checks from the mac implementation of BlockingMutex
Summary: This patch unifies the behavior of BlockingMutex on linux and mac, resolving problems that can arise when BlockingMutex is used in code shared by the two platforms but has different behavior depending on the platform. No longer requires that the calling thread own the mutex for CheckLocked calls to pass. Reviewers: dvyukov, kubamracek Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D29728 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@294614 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 865d9b5 commit fc4a9bf

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

lib/sanitizer_common/sanitizer_mac.cc

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -348,20 +348,16 @@ BlockingMutex::BlockingMutex() {
348348
void BlockingMutex::Lock() {
349349
CHECK(sizeof(OSSpinLock) <= sizeof(opaque_storage_));
350350
CHECK_EQ(OS_SPINLOCK_INIT, 0);
351-
CHECK_NE(owner_, (uptr)pthread_self());
351+
CHECK_EQ(owner_, 0);
352352
OSSpinLockLock((OSSpinLock*)&opaque_storage_);
353-
CHECK(!owner_);
354-
owner_ = (uptr)pthread_self();
355353
}
356354

357355
void BlockingMutex::Unlock() {
358-
CHECK(owner_ == (uptr)pthread_self());
359-
owner_ = 0;
360356
OSSpinLockUnlock((OSSpinLock*)&opaque_storage_);
361357
}
362358

363359
void BlockingMutex::CheckLocked() {
364-
CHECK_EQ((uptr)pthread_self(), owner_);
360+
CHECK_NE(*(OSSpinLock*)&opaque_storage_, 0);
365361
}
366362

367363
u64 NanoTime() {

lib/sanitizer_common/sanitizer_mutex.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ class BlockingMutex {
8383
BlockingMutex();
8484
void Lock();
8585
void Unlock();
86+
87+
// This function does not guarantee an explicit check that the calling thread
88+
// is the thread which owns the mutex. This behavior, while more strictly
89+
// correct, causes problems in cases like StopTheWorld, where a parent thread
90+
// owns the mutex but a child checks that it is locked. Rather than
91+
// maintaining complex state to work around those situations, the check only
92+
// checks that the mutex is owned, and assumes callers to be generally
93+
// well-behaved.
8694
void CheckLocked();
8795
private:
8896
uptr opaque_storage_[10];

0 commit comments

Comments
 (0)