mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-18 14:08:05 +00:00
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:
parent
0f9d3ff6e9
commit
6276e209a7
3 changed files with 12 additions and 11 deletions
|
@ -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,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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -189,4 +189,4 @@ unsigned TaskScheduler::threads()
|
|||
{
|
||||
if (inst) return inst->threadCnt;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue