diff --git a/include/utils/Singleton.h b/include/utils/Singleton.h index ee07df11f4795..2f7c7c2dbf258 100644 --- a/include/utils/Singleton.h +++ b/include/utils/Singleton.h @@ -49,6 +49,18 @@ private: static TYPE* sInstance; }; +/* + * use ANDROID_SINGLETON_STATIC_INSTANCE(TYPE) in your implementation file + * (eg: .cpp) to create the static instance of Singleton<>'s attributes, + * and avoid to have a copy of them in each compilation units Singleton + * is used. + */ + +#define ANDROID_SINGLETON_STATIC_INSTANCE(TYPE) \ + template< class TYPE > Mutex Singleton< TYPE >::sLock; \ + template<> TYPE* Singleton< TYPE >::sInstance(0); + + // --------------------------------------------------------------------------- }; // namespace android diff --git a/libs/surfaceflinger/BufferAllocator.cpp b/libs/surfaceflinger/BufferAllocator.cpp index 28fe81002f9e5..fec7c8770584f 100644 --- a/libs/surfaceflinger/BufferAllocator.cpp +++ b/libs/surfaceflinger/BufferAllocator.cpp @@ -34,8 +34,7 @@ namespace android { // --------------------------------------------------------------------------- -template Mutex Singleton::sLock; -template<> BufferAllocator* Singleton::sInstance(0); +ANDROID_SINGLETON_STATIC_INSTANCE( BufferAllocator ) Mutex BufferAllocator::sLock; KeyedVector BufferAllocator::sAllocList; diff --git a/libs/ui/BufferMapper.cpp b/libs/ui/BufferMapper.cpp index e6ca239831fa3..85a029bcc0d28 100644 --- a/libs/ui/BufferMapper.cpp +++ b/libs/ui/BufferMapper.cpp @@ -44,8 +44,7 @@ namespace android { // --------------------------------------------------------------------------- -template Mutex Singleton::sLock; -template<> BufferMapper* Singleton::sInstance(0); +ANDROID_SINGLETON_STATIC_INSTANCE( BufferMapper ) BufferMapper::BufferMapper() : mAllocMod(0) diff --git a/libs/ui/Surface.cpp b/libs/ui/Surface.cpp index 47880f55151db..fb105b346c7e7 100644 --- a/libs/ui/Surface.cpp +++ b/libs/ui/Surface.cpp @@ -50,8 +50,7 @@ namespace android { // SurfaceBuffer // ============================================================================ -template Mutex Singleton::sLock; -template<> SurfaceBuffer* Singleton::sInstance(0); +ANDROID_SINGLETON_STATIC_INSTANCE( SurfaceBuffer ) SurfaceBuffer::SurfaceBuffer() : BASE(), handle(0), mOwner(false)