From 6276e209a7bc18f25b7a05d15e8ac941e4067058 Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Wed, 14 Apr 2021 20:16:19 +0900 Subject: [PATCH] common initializer: counting engine init count properly. Manage the reference count in common so that all common resources can be initialized/terminated identically. --- src/lib/tvgInitializer.cpp | 12 +++++++++++- src/lib/tvgLoaderMgr.cpp | 9 --------- src/lib/tvgTaskScheduler.cpp | 2 +- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/lib/tvgInitializer.cpp b/src/lib/tvgInitializer.cpp index c91e13e8..039048ab 100644 --- a/src/lib/tvgInitializer.cpp +++ b/src/lib/tvgInitializer.cpp @@ -36,6 +36,8 @@ /* Internal Class Implementation */ /************************************************************************/ +static int _initCnt = 0; + /************************************************************************/ /* External Class Implementation */ @@ -61,6 +63,9 @@ Result Initializer::init(CanvasEngine engine, uint32_t threads) noexcept if (nonSupport) return Result::NonSupport; + if (_initCnt > 0) return Result::Success; + ++_initCnt; + if (!LoaderMgr::init()) return Result::Unknown; TaskScheduler::init(threads); @@ -71,6 +76,8 @@ Result Initializer::init(CanvasEngine engine, uint32_t threads) noexcept Result Initializer::term(CanvasEngine engine) noexcept { + if (_initCnt == 0) return Result::InsufficientCondition; + auto nonSupport = true; if (static_cast(engine) & static_cast(CanvasEngine::Sw)) { @@ -89,9 +96,12 @@ Result Initializer::term(CanvasEngine engine) noexcept if (nonSupport) return Result::NonSupport; + --_initCnt; + if (_initCnt > 0) return Result::Success; + TaskScheduler::term(); if (!LoaderMgr::term()) return Result::Unknown; return Result::Success; -} \ No newline at end of file +} diff --git a/src/lib/tvgLoaderMgr.cpp b/src/lib/tvgLoaderMgr.cpp index 31649ca3..f7feb82b 100644 --- a/src/lib/tvgLoaderMgr.cpp +++ b/src/lib/tvgLoaderMgr.cpp @@ -35,9 +35,6 @@ /* Internal Class Implementation */ /************************************************************************/ -static int initCnt = 0; - - static Loader* _find(FileType type) { switch(type) { @@ -104,9 +101,6 @@ static Loader* _find(const string& path) bool LoaderMgr::init() { - if (initCnt > 0) return true; - ++initCnt; - //TODO: return true; @@ -115,9 +109,6 @@ bool LoaderMgr::init() bool LoaderMgr::term() { - --initCnt; - if (initCnt > 0) return true; - //TODO: return true; diff --git a/src/lib/tvgTaskScheduler.cpp b/src/lib/tvgTaskScheduler.cpp index 63ac4dea..1af381e0 100644 --- a/src/lib/tvgTaskScheduler.cpp +++ b/src/lib/tvgTaskScheduler.cpp @@ -189,4 +189,4 @@ unsigned TaskScheduler::threads() { if (inst) return inst->threadCnt; return 0; -} \ No newline at end of file +}