Native: improve ObjCExport thread state switching
This commit is contained in:
committed by
Space
parent
388538be60
commit
fa36ccedeb
@@ -442,6 +442,20 @@ private:
|
||||
bool reentrant_;
|
||||
};
|
||||
|
||||
// Scopely sets the kRunnable thread state for the current thread,
|
||||
// and initializes runtime if needed for new MM.
|
||||
// No-op for old GC.
|
||||
class CalledFromNativeGuard final : private Pinned {
|
||||
public:
|
||||
ALWAYS_INLINE CalledFromNativeGuard() noexcept;
|
||||
|
||||
~CalledFromNativeGuard() noexcept {
|
||||
SwitchThreadState(thread_, ThreadState::kNative);
|
||||
}
|
||||
private:
|
||||
MemoryState* thread_;
|
||||
};
|
||||
|
||||
template <ThreadState state, typename R, typename... Args>
|
||||
ALWAYS_INLINE inline R CallWithThreadState(R(*function)(Args...), Args... args) {
|
||||
ThreadStateGuard guard(state);
|
||||
|
||||
Reference in New Issue
Block a user