From 41c45b97e70cb7bbef740f0e3ad369f0ebaaf497 Mon Sep 17 00:00:00 2001 From: Ilya Matveev Date: Wed, 26 Jan 2022 20:11:12 +0700 Subject: [PATCH] [K/N][Runtime] Switch thread state when triggering CMS GC --- .../runtime/src/gc/cms/cpp/ConcurrentMarkAndSweep.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/kotlin-native/runtime/src/gc/cms/cpp/ConcurrentMarkAndSweep.cpp b/kotlin-native/runtime/src/gc/cms/cpp/ConcurrentMarkAndSweep.cpp index eae11caa6e2..55981a07aa7 100644 --- a/kotlin-native/runtime/src/gc/cms/cpp/ConcurrentMarkAndSweep.cpp +++ b/kotlin-native/runtime/src/gc/cms/cpp/ConcurrentMarkAndSweep.cpp @@ -85,8 +85,10 @@ gc::ConcurrentMarkAndSweep::ConcurrentMarkAndSweep( objectFactory_(objectFactory), gcScheduler_(gcScheduler), finalizerProcessor_(make_unique([this](int64_t epoch) { state_.finalized(epoch); })) { - gcScheduler_.SetScheduleGC([this]() NO_EXTERNAL_CALLS_CHECK NO_INLINE { + gcScheduler_.SetScheduleGC([this]() NO_INLINE { RuntimeLogDebug({kTagGC}, "Scheduling GC by thread %d", konan::currentThreadId()); + // This call acquires a lock, so we need to ensure that we're in the safe state. + NativeOrUnregisteredThreadGuard guard(/* reentrant = */ true); state_.schedule(); }); gcThread_ = std::thread([this] {