Added runtime init (#846)

This commit is contained in:
Nikolay Igotti
2017-09-11 09:15:22 +03:00
committed by GitHub
parent 60901da0c0
commit 8c5d7a0202
2 changed files with 39 additions and 0 deletions
+15
View File
@@ -45,6 +45,8 @@ void InitOrDeinitGlobalVariables(int initialize) {
}
}
THREAD_LOCAL_VARIABLE RuntimeState* runtimeState = nullptr;
} // namespace
extern "C" {
@@ -67,6 +69,7 @@ RuntimeState* InitRuntime() {
// Keep global variables in state as well.
InitOrDeinitGlobalVariables(true);
konan::consoleInit();
runtimeState = result;
return result;
}
@@ -78,4 +81,16 @@ void DeinitRuntime(RuntimeState* state) {
}
}
void Kotlin_initRuntimeIfNeeded() {
if (runtimeState == nullptr)
runtimeState = InitRuntime();
}
void Kotlin_deinitRuntimeIfNeeded() {
if (runtimeState != nullptr) {
DeinitRuntime(runtimeState);
runtimeState = nullptr;
}
}
} // extern "C"
+24
View File
@@ -0,0 +1,24 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package konan
// Initializes Kotlin runtime for the current thread, if not inited already.
@SymbolName("Kotlin_initRuntimeIfNeeded")
external public fun initRuntimeIfNeeded(): Unit
// Deiitializes Kotlin runtime for the current thread, if was inited.
@SymbolName("Kotlin_deinitRuntimeIfNeeded")
external public fun deinitRuntimeIfNeeded(): Unit