mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
stdlib: avoid posix sched_yield in favour of C++11
Use the C++11 std::this_thread::yield to abstract away platform specific differences for yield execution time. This makes the code more portable to non-POSIX environments (i.e. Windows). NFC.
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
#include <cstring>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <thread>
|
||||
#include "../SwiftShims/RuntimeShims.h"
|
||||
#if SWIFT_OBJC_INTEROP
|
||||
# include <objc/NSObject.h>
|
||||
@@ -766,7 +767,7 @@ HeapObject *swift::swift_weakLoadStrong(WeakReference *ref) {
|
||||
short c = 0;
|
||||
while (__atomic_load_n(&ref->Value, __ATOMIC_RELAXED) & WR_READING) {
|
||||
if (++c == WR_SPINLIMIT) {
|
||||
sched_yield();
|
||||
std::this_thread::yield();
|
||||
c -= 1;
|
||||
}
|
||||
}
|
||||
@@ -815,7 +816,7 @@ void swift::swift_weakCopyInit(WeakReference *dest, WeakReference *src) {
|
||||
short c = 0;
|
||||
while (__atomic_load_n(&src->Value, __ATOMIC_RELAXED) & WR_READING) {
|
||||
if (++c == WR_SPINLIMIT) {
|
||||
sched_yield();
|
||||
std::this_thread::yield();
|
||||
c -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user