[K/N][Runtime] Support thread state switching in spin locks
Issue #KT-49013 Fixed
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user