restore santity check against double creation of singletons
this check may look weird, but in fact a similar check in the old version of the singleton factory helped us spot a problem with Clang, most likely but of the compiler or runtime system
This commit is contained in:
parent
a344604f1b
commit
a889e5ee8b
1 changed files with 14 additions and 0 deletions
|
|
@ -147,6 +147,9 @@ namespace lib {
|
|||
/** storage for the service instance */
|
||||
char buff_[sizeof(TAR)];
|
||||
|
||||
#if NOBUG_MODE_ALPHA
|
||||
static int createCnt;
|
||||
#endif
|
||||
|
||||
/** deleter function to invoke the destructor
|
||||
* of the embedded service object instance.
|
||||
|
|
@ -157,7 +160,9 @@ namespace lib {
|
|||
destroy_in_place (void* pInstance)
|
||||
{
|
||||
if (!pInstance) return;
|
||||
|
||||
static_cast<TAR*> (pInstance) -> ~TAR();
|
||||
ENSURE (0 == --createCnt);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -176,6 +181,7 @@ namespace lib {
|
|||
// place new instance into embedded buffer
|
||||
TAR* newInstance = create_in_buffer<TAR>(buff_);
|
||||
|
||||
ENSURE (0 == createCnt++, "runtime system or compiler broken");
|
||||
try
|
||||
{
|
||||
scheduleDestruction (newInstance, &destroy_in_place);
|
||||
|
|
@ -232,5 +238,13 @@ namespace lib {
|
|||
}
|
||||
|
||||
|
||||
|
||||
#if NOBUG_MODE_ALPHA
|
||||
/** sanity check to guard against re-entrance while instance is still alive.
|
||||
* This helped us in 2013 to spot a compiler bug. */
|
||||
template<typename TAR>
|
||||
int DependencyFactory::InstanceHolder<TAR>::createCnt;
|
||||
#endif
|
||||
|
||||
} // namespace lib
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Reference in a new issue