From c4e2901a1d8f39482642bf504af48412571fe62f Mon Sep 17 00:00:00 2001 From: Pavel Kunyavskiy Date: Tue, 4 Oct 2022 14:49:19 +0200 Subject: [PATCH] [K/N] Avoid inlining of ignored check on external call --- kotlin-native/runtime/src/main/cpp/Mutex.hpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/kotlin-native/runtime/src/main/cpp/Mutex.hpp b/kotlin-native/runtime/src/main/cpp/Mutex.hpp index ea3bc2571ca..c9ade714f26 100644 --- a/kotlin-native/runtime/src/main/cpp/Mutex.hpp +++ b/kotlin-native/runtime/src/main/cpp/Mutex.hpp @@ -36,20 +36,23 @@ class SpinLock; template <> class SpinLock : private Pinned { public: - // No need to check for external calls, because we explicitly ignore thread state. - NO_EXTERNAL_CALLS_CHECK void lock() noexcept { + void lock() noexcept { while(flag_.test_and_set(std::memory_order_acquire)) { - std::this_thread::yield(); + yield(); } } - // No need to check for external calls, because we explicitly ignore thread state. - NO_EXTERNAL_CALLS_CHECK void unlock() noexcept { + void unlock() noexcept { flag_.clear(std::memory_order_release); } private: std::atomic_flag flag_ = ATOMIC_FLAG_INIT; + + // No need to check for external calls, because we explicitly ignore thread state. + static NO_EXTERNAL_CALLS_CHECK NO_INLINE void yield() { + std::this_thread::yield(); + } }; template <>