X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=adaptors%2Fcommon%2Fsingleton-service-impl.cpp;h=5ee61809d60b89fee41617896d46812f69781f16;hb=76f7e9e38f245cc44d21d93a6774b96eee868d3c;hp=fd33464c6f847df2753e7bc9533ccf447470007c;hpb=43d62b88c530b72d2d419da81beffbdb13ec25fc;p=platform%2Fcore%2Fuifw%2Fdali-adaptor.git diff --git a/adaptors/common/singleton-service-impl.cpp b/adaptors/common/singleton-service-impl.cpp index fd33464..5ee6180 100644 --- a/adaptors/common/singleton-service-impl.cpp +++ b/adaptors/common/singleton-service-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2017 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,11 +19,9 @@ #include // EXTERNAL INCLUDES -#include #include // INTERNAL INCLUDES - #if defined(DEBUG_ENABLED) #include Debug::Filter* gSingletonServiceLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_SINGLETON_SERVICE" ); @@ -52,22 +50,7 @@ namespace Adaptor namespace { - -/* - * Dummy cleanup function required as boost::thread_specific_ptr requires access to destructor but - * we should not make the destructor of SingletonService public as it is a ref-counted object. - * - * We do not expect this to be called as we only release the pointer, and not reset. - */ -void DummyCleanup( SingletonService* service ) -{ - if ( service ) - { - service->UnregisterAll(); - } -} - -boost::thread_specific_ptr< SingletonService > gSingletonService( &DummyCleanup ); +thread_local SingletonService * gSingletonService = 0; } // unnamed namespace Dali::SingletonService SingletonService::New() @@ -79,9 +62,9 @@ Dali::SingletonService SingletonService::New() Dali::SingletonService SingletonService::Get() { Dali::SingletonService singletonService; - if ( gSingletonService.get() ) + if ( gSingletonService ) { - singletonService = Dali::SingletonService( gSingletonService.get() ); + singletonService = Dali::SingletonService( gSingletonService ); } return singletonService; } @@ -91,7 +74,7 @@ void SingletonService::Register( const std::type_info& info, BaseHandle singleto if( singleton ) { DALI_LOG_SINGLETON_SERVICE( Debug::General, "Singleton Added: %s\n", info.name() ); - mSingletonContainer.insert( SingletonPair( info.name(), singleton ) ); + mSingletonContainer.push_back( SingletonPair( info.name(), singleton ) ); } } @@ -104,10 +87,14 @@ BaseHandle SingletonService::GetSingleton( const std::type_info& info ) const { BaseHandle object; - SingletonConstIter iter = mSingletonContainer.find(info.name()); - if( iter != mSingletonContainer.end() ) + const SingletonContainer::const_iterator end = mSingletonContainer.end(); + for( SingletonContainer::const_iterator iter = mSingletonContainer.begin(); iter != end; ++iter ) { - object = ( *iter ).second; + // comparing the addresses as these are allocated statically per library + if( ( *iter ).first == info.name() ) + { + object = ( *iter ).second; + } } return object; @@ -117,16 +104,17 @@ SingletonService::SingletonService() : mSingletonContainer() { // Can only have one instance of SingletonService - DALI_ASSERT_ALWAYS( !gSingletonService.get() && "Only one instance of SingletonService is allowed"); + DALI_ASSERT_ALWAYS( !gSingletonService && "Only one instance of SingletonService is allowed"); - gSingletonService.reset( this ); + gSingletonService = this; DALI_LOG_SINGLETON_SERVICE_DIRECT( Debug::Concise, "SingletonService Created\n" ); } SingletonService::~SingletonService() { - gSingletonService.release(); + gSingletonService = 0; + DALI_LOG_SINGLETON_SERVICE_DIRECT( Debug::Concise, "SingletonService Destroyed\n" ); } @@ -135,3 +123,4 @@ SingletonService::~SingletonService() } // namespace Internal } // namespace Dali +