author | simon <simon> | 2002-12-14 17:55:12 (UTC) |
---|---|---|
committer | simon <simon> | 2002-12-14 17:55:12 (UTC) |
commit | 309c34a61e7cf6a199275c32c00ec1eaaa511d9b (patch) (side-by-side diff) | |
tree | 5aa46eaefc040373397fcb3157ae6b5dd46a9c49 /noncore/multimedia/opieplayer2/singleton.h | |
parent | 03c4518324c328c530eb795705b6a4281d65055a (diff) | |
download | opie-309c34a61e7cf6a199275c32c00ec1eaaa511d9b.zip opie-309c34a61e7cf6a199275c32c00ec1eaaa511d9b.tar.gz opie-309c34a61e7cf6a199275c32c00ec1eaaa511d9b.tar.bz2 |
- make it thread-safe
Diffstat (limited to 'noncore/multimedia/opieplayer2/singleton.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/multimedia/opieplayer2/singleton.h | 13 |
1 files changed, 11 insertions, 2 deletions
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 @@ -21,4 +21,6 @@ #define SINGLETON_H +#include "threadutil.h" + template <class Product> struct DefaultSingletonCreator @@ -43,6 +45,9 @@ public: static T &self() { - if ( !s_self ) - s_self = Creator<T>::create(); + if ( !s_self ) { + ThreadUtil::AutoLock lock( s_guard ); + if ( !s_self ) + s_self = Creator<T>::create(); + } return *s_self; } @@ -59,4 +64,5 @@ private: static T *s_self; + static ThreadUtil::Mutex s_guard; }; @@ -64,4 +70,7 @@ template <class T, template <class> class Creator> T *Singleton<T, Creator>::s_self = 0; +template <class T, template <class> class Creator> +ThreadUtil::Mutex Singleton<T, Creator>::s_guard; + #endif // SINGLETON_H /* vim: et sw=4 ts=4 |