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:
Saleem Abdulrasool
2016-06-15 08:51:37 -07:00
parent 78c04e2218
commit 91a296fad6

View File

@@ -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;
}
}