Fixed bug 1776032 by changing class to singleton.
git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@985 7ec92016-0320-0410-acc4-a06ded1c099a
This commit is contained in:
parent
26d771c3a1
commit
4b43d68311
1 changed files with 28 additions and 14 deletions
|
@ -523,6 +523,19 @@ namespace Loki
|
|||
{
|
||||
struct Initializer
|
||||
{
|
||||
|
||||
/// This function provides a Scott-Meyers type of Singleton as the initializer
|
||||
/// for the shared mutex.
|
||||
static Initializer & GetIt( void )
|
||||
{
|
||||
static Initializer initializer_;
|
||||
return initializer_;
|
||||
}
|
||||
|
||||
inline bool IsInit( void ) { return init_; }
|
||||
inline MutexPolicy & GetMutex( void ) { return mtx_; }
|
||||
|
||||
private:
|
||||
bool init_;
|
||||
MutexPolicy mtx_;
|
||||
|
||||
|
@ -535,9 +548,10 @@ namespace Loki
|
|||
{
|
||||
assert(init_);
|
||||
}
|
||||
};
|
||||
|
||||
static Initializer initializer_;
|
||||
Initializer( const Initializer & );
|
||||
Initializer & operator = ( const Initializer & );
|
||||
};
|
||||
|
||||
public:
|
||||
|
||||
|
@ -553,29 +567,33 @@ namespace Loki
|
|||
/// Lock class
|
||||
Lock()
|
||||
{
|
||||
assert(initializer_.init_);
|
||||
initializer_.mtx_.Lock();
|
||||
Initializer & initializer = Initializer::GetIt();
|
||||
assert( initializer.IsInit() );
|
||||
initializer.GetMutex().Lock();
|
||||
}
|
||||
|
||||
/// Lock class
|
||||
explicit Lock(const ClassLevelLockable&)
|
||||
{
|
||||
assert(initializer_.init_);
|
||||
initializer_.mtx_.Lock();
|
||||
Initializer & initializer = Initializer::GetIt();
|
||||
assert( initializer.IsInit() );
|
||||
initializer.GetMutex().Lock();
|
||||
}
|
||||
|
||||
/// Lock class
|
||||
explicit Lock(const ClassLevelLockable*)
|
||||
{
|
||||
assert(initializer_.init_);
|
||||
initializer_.mtx_.Lock();
|
||||
Initializer & initializer = Initializer::GetIt();
|
||||
assert( initializer.IsInit() );
|
||||
initializer.GetMutex().Lock();
|
||||
}
|
||||
|
||||
/// Unlock class
|
||||
~Lock()
|
||||
{
|
||||
assert(initializer_.init_);
|
||||
initializer_.mtx_.Unlock();
|
||||
Initializer & initializer = Initializer::GetIt();
|
||||
assert( initializer.IsInit() );
|
||||
initializer.GetMutex().Unlock();
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -596,10 +614,6 @@ namespace Loki
|
|||
pthread_mutex_t ClassLevelLockable<Host, MutexPolicy>::atomic_mutex_ = PTHREAD_MUTEX_INITIALIZER;
|
||||
#endif
|
||||
|
||||
template < class Host, class MutexPolicy >
|
||||
typename ClassLevelLockable< Host, MutexPolicy >::Initializer
|
||||
ClassLevelLockable< Host, MutexPolicy >::initializer_;
|
||||
|
||||
#endif // #if defined(LOKI_WINDOWS_H) || defined(LOKI_PTHREAD_H)
|
||||
|
||||
} // namespace Loki
|
||||
|
|
Loading…
Reference in a new issue