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
|
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_;
|
bool init_;
|
||||||
MutexPolicy mtx_;
|
MutexPolicy mtx_;
|
||||||
|
|
||||||
|
@ -535,9 +548,10 @@ namespace Loki
|
||||||
{
|
{
|
||||||
assert(init_);
|
assert(init_);
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
static Initializer initializer_;
|
Initializer( const Initializer & );
|
||||||
|
Initializer & operator = ( const Initializer & );
|
||||||
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -553,29 +567,33 @@ namespace Loki
|
||||||
/// Lock class
|
/// Lock class
|
||||||
Lock()
|
Lock()
|
||||||
{
|
{
|
||||||
assert(initializer_.init_);
|
Initializer & initializer = Initializer::GetIt();
|
||||||
initializer_.mtx_.Lock();
|
assert( initializer.IsInit() );
|
||||||
|
initializer.GetMutex().Lock();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Lock class
|
/// Lock class
|
||||||
explicit Lock(const ClassLevelLockable&)
|
explicit Lock(const ClassLevelLockable&)
|
||||||
{
|
{
|
||||||
assert(initializer_.init_);
|
Initializer & initializer = Initializer::GetIt();
|
||||||
initializer_.mtx_.Lock();
|
assert( initializer.IsInit() );
|
||||||
|
initializer.GetMutex().Lock();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Lock class
|
/// Lock class
|
||||||
explicit Lock(const ClassLevelLockable*)
|
explicit Lock(const ClassLevelLockable*)
|
||||||
{
|
{
|
||||||
assert(initializer_.init_);
|
Initializer & initializer = Initializer::GetIt();
|
||||||
initializer_.mtx_.Lock();
|
assert( initializer.IsInit() );
|
||||||
|
initializer.GetMutex().Lock();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Unlock class
|
/// Unlock class
|
||||||
~Lock()
|
~Lock()
|
||||||
{
|
{
|
||||||
assert(initializer_.init_);
|
Initializer & initializer = Initializer::GetIt();
|
||||||
initializer_.mtx_.Unlock();
|
assert( initializer.IsInit() );
|
||||||
|
initializer.GetMutex().Unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -596,10 +614,6 @@ namespace Loki
|
||||||
pthread_mutex_t ClassLevelLockable<Host, MutexPolicy>::atomic_mutex_ = PTHREAD_MUTEX_INITIALIZER;
|
pthread_mutex_t ClassLevelLockable<Host, MutexPolicy>::atomic_mutex_ = PTHREAD_MUTEX_INITIALIZER;
|
||||||
#endif
|
#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)
|
#endif // #if defined(LOKI_WINDOWS_H) || defined(LOKI_PTHREAD_H)
|
||||||
|
|
||||||
} // namespace Loki
|
} // namespace Loki
|
||||||
|
|
Loading…
Reference in a new issue