[compiler-rt] 840a16d - Revert "[darwin] switch blocking mutex from osspinlock to os_unfair_lock"

Hans Wennborg via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 4 03:23:06 PST 2021


Author: Hans Wennborg
Date: 2021-03-04T12:22:39+01:00
New Revision: 840a16d3c4cbb193dde4e1f41f9137a2a234d0f8

URL: https://github.com/llvm/llvm-project/commit/840a16d3c4cbb193dde4e1f41f9137a2a234d0f8
DIFF: https://github.com/llvm/llvm-project/commit/840a16d3c4cbb193dde4e1f41f9137a2a234d0f8.diff

LOG: Revert "[darwin] switch blocking mutex from osspinlock to os_unfair_lock"

> OSSpinLock is deprecated, so we are switching to `os_unfair_lock`. However, `os_unfair_lock` isn't available on older OSs, so we keep `OSSpinLock` as fallback.
>
> Also change runtime assumption check to static since they only ever check constant values.
>
> rdar://69588111
>
> Reviewed By: delcypher, yln
>
> Differential Revision: https://reviews.llvm.org/D97509

This reverts commit 71ef54337d5e83c6767e4816227ef340caa337fc.

Added: 
    

Modified: 
    compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp
index f7c216a90acd..b0d7bcc645fa 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp
@@ -70,7 +70,6 @@ extern "C" {
 #include <mach/mach_time.h>
 #include <mach/vm_statistics.h>
 #include <malloc/malloc.h>
-#include <os/lock.h>
 #include <os/log.h>
 #include <pthread.h>
 #include <sched.h>
@@ -507,42 +506,22 @@ void MprotectMallocZones(void *addr, int prot) {
 }
 
 BlockingMutex::BlockingMutex() {
-  // Initialize all member variables to 0
   internal_memset(this, 0, sizeof(*this));
-  static_assert(sizeof(os_unfair_lock_t) <= sizeof(opaque_storage_),
-                "Not enough space in opaque storage to use os_unfair_lock");
-  static_assert(sizeof(OSSpinLock) <= sizeof(opaque_storage_),
-                "Not enough space in opaque storage to use OSSpinLock");
 }
 
-static bool UnfairLockAvailable() { return bool(os_unfair_lock_lock); }
-static_assert(OS_UNFAIR_LOCK_INIT._os_unfair_lock_opaque == 0,
-              "os_unfair_lock does not initialize to 0");
-static_assert(OS_SPINLOCK_INIT == 0, "OSSpinLock does not initialize to 0");
-
 void BlockingMutex::Lock() {
+  CHECK(sizeof(OSSpinLock) <= sizeof(opaque_storage_));
+  CHECK_EQ(OS_SPINLOCK_INIT, 0);
   CHECK_EQ(owner_, 0);
-  if (UnfairLockAvailable()) {
-    os_unfair_lock_lock((os_unfair_lock *)&opaque_storage_);
-  } else {
-    OSSpinLockLock((OSSpinLock *)&opaque_storage_);
-  }
+  OSSpinLockLock((OSSpinLock*)&opaque_storage_);
 }
 
 void BlockingMutex::Unlock() {
-  if (UnfairLockAvailable()) {
-    os_unfair_lock_unlock((os_unfair_lock *)&opaque_storage_);
-  } else {
-    OSSpinLockUnlock((OSSpinLock *)&opaque_storage_);
-  }
+  OSSpinLockUnlock((OSSpinLock*)&opaque_storage_);
 }
 
 void BlockingMutex::CheckLocked() {
-  if (UnfairLockAvailable()) {
-    CHECK_NE((*(os_unfair_lock *)&opaque_storage_)._os_unfair_lock_opaque, 0);
-  } else {
-    CHECK_NE(*(OSSpinLock *)&opaque_storage_, 0);
-  }
+  CHECK_NE(*(OSSpinLock*)&opaque_storage_, 0);
 }
 
 u64 NanoTime() {


        


More information about the llvm-commits mailing list