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:
parent
dddd95d48d
commit
c4e9df64c2
1 changed files with 10 additions and 15 deletions
|
@ -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();
|
||||
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_);
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue