Skip to content

[Runtime] Use os_unfair_lock for Mutex and StaticMutex on Darwin. #34598

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions include/swift/Runtime/Concurrent.h
Original file line number Diff line number Diff line change
Expand Up @@ -508,8 +508,8 @@ template <class ElemTy> struct ConcurrentReadableArray {
}

void push_back(const ElemTy &elem) {
ScopedLock guard(WriterLock);
Mutex::ScopedLock guard(WriterLock);

auto *storage = Elements.load(std::memory_order_relaxed);
auto count = storage ? storage->Count.load(std::memory_order_relaxed) : 0;
if (count >= Capacity) {
Expand Down Expand Up @@ -594,9 +594,6 @@ struct ConcurrentReadableHashMap {
"Elements must not have destructors (they won't be called).");

private:
// A scoped lock type to use on MutexTy.
using ScopedLockTy = ScopedLockT<MutexTy, false>;

/// The reciprocal of the load factor at which we expand the table. A value of
/// 4 means that we resize at 1/4 = 75% load factor.
static const size_t ResizeProportion = 4;
Expand Down Expand Up @@ -970,7 +967,7 @@ struct ConcurrentReadableHashMap {
/// The return value is ignored when `created` is `false`.
template <class KeyTy, typename Call>
void getOrInsert(KeyTy key, const Call &call) {
ScopedLockTy guard(WriterLock);
typename MutexTy::ScopedLock guard(WriterLock);

auto *indices = Indices.load(std::memory_order_relaxed);
if (!indices)
Expand Down Expand Up @@ -1022,7 +1019,7 @@ struct ConcurrentReadableHashMap {
/// Clear the hash table, freeing (when safe) all memory currently used for
/// indices and elements.
void clear() {
ScopedLockTy guard(WriterLock);
typename MutexTy::ScopedLock guard(WriterLock);

auto *indices = Indices.load(std::memory_order_relaxed);
auto *elements = Elements.load(std::memory_order_relaxed);
Expand Down
Loading