Native: improve ObjCExport thread state switching
This commit is contained in:
committed by
Space
parent
388538be60
commit
fa36ccedeb
@@ -465,18 +465,21 @@ extern "C" void EnsureNeverFrozen(ObjHeader* obj) {
|
||||
}
|
||||
|
||||
extern "C" ForeignRefContext InitLocalForeignRef(ObjHeader* object) {
|
||||
AssertThreadState(ThreadState::kRunnable);
|
||||
// TODO: Remove when legacy MM is gone.
|
||||
// Nothing to do.
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
extern "C" ForeignRefContext InitForeignRef(ObjHeader* object) {
|
||||
AssertThreadState(ThreadState::kRunnable);
|
||||
auto* threadData = mm::ThreadRegistry::Instance().CurrentThreadData();
|
||||
auto* node = mm::StableRefRegistry::Instance().RegisterStableRef(threadData, object);
|
||||
return ToForeignRefManager(node);
|
||||
}
|
||||
|
||||
extern "C" void DeinitForeignRef(ObjHeader* object, ForeignRefContext context) {
|
||||
AssertThreadState(ThreadState::kRunnable);
|
||||
RuntimeAssert(context != nullptr, "DeinitForeignRef must not be called for InitLocalForeignRef");
|
||||
auto* threadData = mm::ThreadRegistry::Instance().CurrentThreadData();
|
||||
auto* node = FromForeignRefManager(context);
|
||||
@@ -529,4 +532,10 @@ MemoryState* kotlin::mm::GetMemoryState() {
|
||||
return ToMemoryState(ThreadRegistry::Instance().CurrentThreadDataNode());
|
||||
}
|
||||
|
||||
ALWAYS_INLINE kotlin::CalledFromNativeGuard::CalledFromNativeGuard() noexcept {
|
||||
Kotlin_initRuntimeIfNeeded();
|
||||
thread_ = mm::GetMemoryState();
|
||||
SwitchThreadState(thread_, ThreadState::kRunnable);
|
||||
}
|
||||
|
||||
const bool kotlin::kSupportsMultipleMutators = kotlin::gc::kSupportsMultipleMutators;
|
||||
|
||||
Reference in New Issue
Block a user