Skip to content

Commit 768a085

Browse files
authored
Merge pull request #34598 from mikeash/os-unfair-lock-mutex
[Runtime] Use os_unfair_lock for Mutex and StaticMutex on Darwin.
2 parents a7e8352 + e82d9e8 commit 768a085

File tree

9 files changed

+509
-223
lines changed

9 files changed

+509
-223
lines changed

include/swift/Runtime/Concurrent.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -508,8 +508,8 @@ template <class ElemTy> struct ConcurrentReadableArray {
508508
}
509509

510510
void push_back(const ElemTy &elem) {
511-
ScopedLock guard(WriterLock);
512-
511+
Mutex::ScopedLock guard(WriterLock);
512+
513513
auto *storage = Elements.load(std::memory_order_relaxed);
514514
auto count = storage ? storage->Count.load(std::memory_order_relaxed) : 0;
515515
if (count >= Capacity) {
@@ -594,9 +594,6 @@ struct ConcurrentReadableHashMap {
594594
"Elements must not have destructors (they won't be called).");
595595

596596
private:
597-
// A scoped lock type to use on MutexTy.
598-
using ScopedLockTy = ScopedLockT<MutexTy, false>;
599-
600597
/// The reciprocal of the load factor at which we expand the table. A value of
601598
/// 4 means that we resize at 1/4 = 75% load factor.
602599
static const size_t ResizeProportion = 4;
@@ -1043,7 +1040,7 @@ struct ConcurrentReadableHashMap {
10431040
/// The return value is ignored when `created` is `false`.
10441041
template <class KeyTy, typename Call>
10451042
void getOrInsert(KeyTy key, const Call &call) {
1046-
ScopedLockTy guard(WriterLock);
1043+
typename MutexTy::ScopedLock guard(WriterLock);
10471044

10481045
auto indices = IndexStorage{Indices.load(std::memory_order_relaxed)};
10491046
auto indicesCapacityLog2 = indices.getCapacityLog2();
@@ -1092,7 +1089,7 @@ struct ConcurrentReadableHashMap {
10921089
/// Clear the hash table, freeing (when safe) all memory currently used for
10931090
/// indices and elements.
10941091
void clear() {
1095-
ScopedLockTy guard(WriterLock);
1092+
typename MutexTy::ScopedLock guard(WriterLock);
10961093

10971094
IndexStorage indices = Indices.load(std::memory_order_relaxed);
10981095
auto *elements = Elements.load(std::memory_order_relaxed);

0 commit comments

Comments
 (0)