changed the position of the mmgr parameter in some constructors.

removed StdMmgr::getInstance() and initialized the default mmgr inside Mmgr::getDFL() to work around an issue related to c++ initialization order across translation units
This commit is contained in:
2018-10-31 10:40:25 +00:00
parent b01cf731ca
commit efc34cdd69
26 changed files with 87 additions and 88 deletions

View File

@ -36,12 +36,7 @@ struct xma_xtn_t
HeapMmgr* heap;
};
HeapMmgr::HeapMmgr (qse_size_t heap_size) QSE_CPP_NOEXCEPT:
Mmgr(), Mmged(QSE_NULL), xma(QSE_NULL), heap_size (heap_size)
{
}
HeapMmgr::HeapMmgr (Mmgr* mmgr, qse_size_t heap_size) QSE_CPP_NOEXCEPT:
HeapMmgr::HeapMmgr (qse_size_t heap_size, Mmgr* mmgr) QSE_CPP_NOEXCEPT:
Mmgr(), Mmged(mmgr), xma(QSE_NULL), heap_size (heap_size)
{
}

View File

@ -54,10 +54,26 @@ void* Mmgr::callocate (qse_size_t n, bool raise_exception) QSE_CPP_THREXCEPT1(Me
return ptr;
}
Mmgr* Mmgr::dfl_mmgr = StdMmgr::getInstance();
#if 0
#if defined(__GNUC__)
static StdMmgr __attribute__((init_priority(101))) std_dfl_mmgr;
#else
static StdMmgr std_dfl_mmgr;
#endif
Mmgr* Mmgr::dfl_mmgr = &std_dfl_mmgr;
//Mmgr* Mmgr::dfl_mmgr = StdMmgr::getInstance(); <--- has an issue with initialization order
#else
// C++ initialization order across translation units are not defined.
// so it's tricky to work around this... the init_priority attribute
// can solve this problem. but it's compiler dependent.
// Mmgr::getDFL() resets dfl_mmgr to &std_dfl_mmgr if it's NULL.
Mmgr* Mmgr::dfl_mmgr = QSE_NULL;
#endif
Mmgr* Mmgr::getDFL () QSE_CPP_NOEXCEPT
{
static StdMmgr std_dfl_mmgr;
if (!Mmgr::dfl_mmgr) Mmgr::dfl_mmgr = &std_dfl_mmgr;
return Mmgr::dfl_mmgr;
}

View File

@ -47,11 +47,14 @@ void StdMmgr::freeMem (void* ptr) QSE_CPP_NOEXCEPT
::free (ptr);
}
#if 0
StdMmgr* StdMmgr::getInstance () QSE_CPP_NOEXCEPT
{
static StdMmgr DFL;
return &DFL;
}
#endif
/////////////////////////////////
QSE_END_NAMESPACE(QSE)