Rework deinit sequence to avoid bogus leak detector warnings.
This commit is contained in:
@@ -127,7 +127,7 @@ void onThreadExit(void (*destructor)()) {
|
|||||||
#ifdef KONAN_WASM
|
#ifdef KONAN_WASM
|
||||||
// No way to do that.
|
// No way to do that.
|
||||||
#else
|
#else
|
||||||
::atexit(destructor);
|
#error "How to do onThreadExit()?"
|
||||||
#endif
|
#endif
|
||||||
#else // !KONAN_NO_THREADS
|
#else // !KONAN_NO_THREADS
|
||||||
// We cannot use pthread_cleanup_push() as it is lexical scope bound.
|
// We cannot use pthread_cleanup_push() as it is lexical scope bound.
|
||||||
|
|||||||
@@ -82,15 +82,6 @@ void Kotlin_initRuntimeIfNeeded() {
|
|||||||
runtimeState = initRuntime();
|
runtimeState = initRuntime();
|
||||||
// Register runtime deinit function at thread cleanup.
|
// Register runtime deinit function at thread cleanup.
|
||||||
konan::onThreadExit(Kotlin_deinitRuntimeIfNeeded);
|
konan::onThreadExit(Kotlin_deinitRuntimeIfNeeded);
|
||||||
#ifndef KONAN_WASM
|
|
||||||
// `onThreadExit` doesn't work on main thread, use `atexit`:
|
|
||||||
|
|
||||||
static bool deinitScheduledAtexit = false;
|
|
||||||
if (!deinitScheduledAtexit) {
|
|
||||||
deinitScheduledAtexit = true; // Having data race is OK here.
|
|
||||||
::atexit(Kotlin_deinitRuntimeIfNeeded);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user