Skip to content

Commit cd7d4ed

Browse files
committed
fixup mac os
1 parent 63f6551 commit cd7d4ed

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

compiler/threading/locks.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@
1515
class CustomMutex {
1616
public:
1717
void Lock() {
18+
#ifdef __APPLE__
19+
int old = kFree;
20+
21+
while (!state_.compare_exchange_strong(old, kLockedWithWaiters)) {
22+
usleep(250);
23+
old = kFree;
24+
}
25+
#else
1826
int old = kFree;
1927
if (state_.compare_exchange_strong(old, kLockedNoWaiters)) {
2028
return;
@@ -27,13 +35,18 @@ class CustomMutex {
2735
syscall(SYS_futex, &state_, FUTEX_WAIT, kLockedWithWaiters, 0, 0, 0);
2836
old = state_.exchange(kLockedWithWaiters);
2937
}
38+
#endif
3039
}
3140

3241
void Unlock() {
42+
#ifdef __APPLE__
43+
state_.store(kFree);
44+
#else
3345
if (state_.fetch_sub(1) == kLockedWithWaiters) {
3446
state_.store(kFree);
3547
syscall(SYS_futex, &state_, FUTEX_WAKE, 1, 0, 0, 0); // wake one
3648
}
49+
#endif
3750
}
3851

3952
// https://en.cppreference.com/w/cpp/named_req/BasicLockable

0 commit comments

Comments
 (0)