From a619b78954c612d09a296f081af994bce7d575f6 Mon Sep 17 00:00:00 2001 From: Ilya Matveev Date: Thu, 30 Sep 2021 17:12:50 +0700 Subject: [PATCH] [K/N][Runtime] Call yield in SpinLock's loop --- kotlin-native/runtime/src/main/cpp/Mutex.hpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/kotlin-native/runtime/src/main/cpp/Mutex.hpp b/kotlin-native/runtime/src/main/cpp/Mutex.hpp index 80545175b90..bcd3b3f7ff6 100644 --- a/kotlin-native/runtime/src/main/cpp/Mutex.hpp +++ b/kotlin-native/runtime/src/main/cpp/Mutex.hpp @@ -18,6 +18,7 @@ #define RUNTIME_MUTEX_H #include +#include #include "KAssert.h" #include "Memory.h" @@ -37,7 +38,7 @@ class SpinLock : 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(); } }