[K/N][Runtime] Support thread state switching in spin locks

Issue #KT-49013 Fixed
This commit is contained in:
Ilya Matveev
2021-09-28 17:29:42 +07:00
committed by Space
parent bee44c6e0f
commit 629ea1036e
15 changed files with 223 additions and 50 deletions
@@ -497,6 +497,20 @@ ALWAYS_INLINE inline R CallWithThreadState(R(*function)(Args...), Args... args)
return function(std::forward<Args>(args)...);
}
class NativeOrUnregisteredThreadGuard final : private MoveOnly {
public:
explicit NativeOrUnregisteredThreadGuard(bool reentrant = false) noexcept {
// The default ctor of ThreadStateGuard doesn't set the state.
// So the actual state switching is performed only if the thread is registered.
if (kotlin::mm::IsCurrentThreadRegistered()) {
backingGuard_ = kotlin::ThreadStateGuard(kotlin::ThreadState::kNative, reentrant);
}
}
private:
ThreadStateGuard backingGuard_;
};
extern const bool kSupportsMultipleMutators;
} // namespace kotlin