common initializer: counting engine init count properly.

Manage the reference count in common so that
all common resources can be initialized/terminated identically.
This commit is contained in:
Hermet Park 2021-04-14 20:16:19 +09:00
parent 0f9d3ff6e9
commit 6276e209a7
3 changed files with 12 additions and 11 deletions

View file

@ -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<uint32_t>(engine) & static_cast<uint32_t>(CanvasEngine::Sw)) {
@ -89,6 +96,9 @@ 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;

View file

@ -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;