From 309c34a61e7cf6a199275c32c00ec1eaaa511d9b Mon Sep 17 00:00:00 2001 From: simon Date: Sat, 14 Dec 2002 17:55:12 +0000 Subject: - make it thread-safe --- (limited to 'noncore/multimedia/opieplayer2/singleton.h') diff --git a/noncore/multimedia/opieplayer2/singleton.h b/noncore/multimedia/opieplayer2/singleton.h index 83e228f..825344e 100644 --- a/noncore/multimedia/opieplayer2/singleton.h +++ b/noncore/multimedia/opieplayer2/singleton.h @@ -20,6 +20,8 @@ #ifndef SINGLETON_H #define SINGLETON_H +#include "threadutil.h" + template struct DefaultSingletonCreator { @@ -42,8 +44,11 @@ class Singleton public: static T &self() { - if ( !s_self ) - s_self = Creator::create(); + if ( !s_self ) { + ThreadUtil::AutoLock lock( s_guard ); + if ( !s_self ) + s_self = Creator::create(); + } return *s_self; } @@ -58,11 +63,15 @@ private: Singleton &operator=( const Singleton &rhs ); static T *s_self; + static ThreadUtil::Mutex s_guard; }; template class Creator> T *Singleton::s_self = 0; +template class Creator> +ThreadUtil::Mutex Singleton::s_guard; + #endif // SINGLETON_H /* vim: et sw=4 ts=4 */ -- cgit v0.9.0.2