From 801953ec565d9ea9a04fc8c2a25f9a02c271d7b4 Mon Sep 17 00:00:00 2001 From: Konstantin Anisimov Date: Fri, 16 Dec 2016 18:19:01 +0300 Subject: [PATCH] RUNTIME: laucher uses runtime API for registering and running out initializers --- runtime/src/launcher/cpp/launcher.cpp | 27 --------------------------- runtime/src/main/cpp/Types.cpp | 19 +++++++++++++++++++ runtime/src/main/cpp/Types.h | 9 +++++++++ 3 files changed, 28 insertions(+), 27 deletions(-) diff --git a/runtime/src/launcher/cpp/launcher.cpp b/runtime/src/launcher/cpp/launcher.cpp index 597bd15d94f..1ade5733872 100644 --- a/runtime/src/launcher/cpp/launcher.cpp +++ b/runtime/src/launcher/cpp/launcher.cpp @@ -3,33 +3,6 @@ #include "Natives.h" #include "Types.h" -//--- Init global variables ---------------------------------------------------// - -typedef void (*Initializer)(); -struct InitNode; - -struct InitNode { - Initializer init; - struct InitNode* next; -}; - -static struct InitNode initHeadNode; -static struct InitNode* initTailNode = &initHeadNode; - - -void InitGlobalVariables() { - struct InitNode *currNode = initHeadNode.next; - while(currNode) { - currNode->init(); - currNode = currNode->next; - } -} - -extern "C" void appendToInitializersTail(struct InitNode *next) { - initTailNode->next = next; - initTailNode = next; -} - //--- Setup args --------------------------------------------------------------// ObjHeader* setupArgs(int argc, char** argv) { diff --git a/runtime/src/main/cpp/Types.cpp b/runtime/src/main/cpp/Types.cpp index 3049610a095..3724e9dd8a9 100644 --- a/runtime/src/main/cpp/Types.cpp +++ b/runtime/src/main/cpp/Types.cpp @@ -31,6 +31,25 @@ void CheckInstance(const ObjHeader* obj, const TypeInfo* type_info) { ThrowClassCastException(); } +static struct InitNode* initHeadNode = nullptr; +static struct InitNode* initTailNode = nullptr; + +void AppendToInitializersTail(struct InitNode *next) { + if (initHeadNode == nullptr) { + initHeadNode = next; + } else { + initTailNode->next = next; + } + initTailNode = next; +} + +void InitGlobalVariables() { + struct InitNode *currNode = initHeadNode; + while(currNode != nullptr) { + currNode->init(); + currNode = currNode->next; + } +} #ifdef __cplusplus } #endif diff --git a/runtime/src/main/cpp/Types.h b/runtime/src/main/cpp/Types.h index dde452d8707..8f1d23b5ed2 100644 --- a/runtime/src/main/cpp/Types.h +++ b/runtime/src/main/cpp/Types.h @@ -39,6 +39,15 @@ extern const TypeInfo* theThrowableTypeInfo; KBoolean IsInstance(const ObjHeader* obj, const TypeInfo* type_info); void CheckCast(const ObjHeader* obj, const TypeInfo* type_info); +typedef void (*Initializer)(); +struct InitNode { + Initializer init; + struct InitNode* next; +}; + +void AppendToInitializersTail(struct InitNode*); +void InitGlobalVariables(); + #ifdef __cplusplus } #endif