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
|
||||
// No way to do that.
|
||||
#else
|
||||
::atexit(destructor);
|
||||
#error "How to do onThreadExit()?"
|
||||
#endif
|
||||
#else // !KONAN_NO_THREADS
|
||||
// We cannot use pthread_cleanup_push() as it is lexical scope bound.
|
||||
|
||||
@@ -82,15 +82,6 @@ void Kotlin_initRuntimeIfNeeded() {
|
||||
runtimeState = initRuntime();
|
||||
// Register runtime deinit function at thread cleanup.
|
||||
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