Skip to content

Commit 0b4ea77

Browse files
committed
[Threading] Fix C11 once implementation to not rely on lock recursion.
The implementation mistakenly locked and unlocked the mutex in `helper.once_wait()`, which is only ever called from inside a region where the mutex is already locked. rdar://119739594
1 parent c5840e8 commit 0b4ea77

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib/Threading/C11.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ class C11ThreadingHelper {
4343
void once_unlock() { SWIFT_C11THREADS_CHECK(mtx_unlock(&onceMutex_)); }
4444
void once_broadcast() { SWIFT_C11THREADS_CHECK(cnd_broadcast(&onceCond_)); }
4545
void once_wait() {
46-
SWIFT_C11THREADS_CHECK(mtx_lock(&onceMutex_));
46+
// The mutex must be locked when this function is entered. It will
47+
// be locked again before the function returns.
4748
SWIFT_C11THREADS_CHECK(cnd_wait(&onceCond_, &onceMutex_));
48-
SWIFT_C11THREADS_CHECK(mtx_unlock(&onceMutex_));
4949
}
5050
};
5151

0 commit comments

Comments
 (0)