[K/N][Runtime] Call yield in SpinLock's loop

This commit is contained in:
Ilya Matveev
2021-09-30 17:12:50 +07:00
committed by Space
parent 629ea1036e
commit a619b78954
+3 -2
View File
@@ -18,6 +18,7 @@
#define RUNTIME_MUTEX_H
#include <cstdint>
#include <thread>
#include "KAssert.h"
#include "Memory.h"
@@ -37,7 +38,7 @@ class SpinLock<MutexThreadStateHandling::kIgnore> : private Pinned {
public:
void lock() noexcept {
while (!__sync_bool_compare_and_swap(&atomicInt, 0, 1)) {
// TODO: yield.
std::this_thread::yield();
}
}
@@ -63,7 +64,7 @@ public:
kotlin::NativeOrUnregisteredThreadGuard guard(/* reentrant = */ true);
while (!__sync_bool_compare_and_swap(&atomicInt, 0, 1)) {
// TODO: yield.
std::this_thread::yield();
}
}