asserts to catch >static initialization order fiasco<

git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@180 7ec92016-0320-0410-acc4-a06ded1c099a
This commit is contained in:
syntheticpp 2005-07-27 16:32:20 +00:00
parent dddd95d48d
commit c4e9df64c2

View file

@ -140,20 +140,16 @@ namespace Loki
CRITICAL_SECTION mtx_;
bool init_;
Initializer()
{
init();
}
~Initializer()
{
assert( init_ );
::DeleteCriticalSection(&mtx_);
}
void init()
Initializer():init_(false)
{
::InitializeCriticalSection(&mtx_);
init_=true;
}
~Initializer()
{
assert(init_);
::DeleteCriticalSection(&mtx_);
}
};
static Initializer initializer_;
@ -169,18 +165,17 @@ namespace Loki
public:
Lock()
{
assert( initializer_.init_ );
//if(!initializer_.init_) initializer_.init();
::EnterCriticalSection(&initializer_.mtx_);
assert(initializer_.init_);
::EnterCriticalSection(&initializer_.mtx_);
}
explicit Lock(const ClassLevelLockable&)
{
assert( initializer_.init_ );
assert(initializer_.init_);
::EnterCriticalSection(&initializer_.mtx_);
}
~Lock()
{
assert( initializer_.init_ );
assert(initializer_.init_);
::LeaveCriticalSection(&initializer_.mtx_);
}
};