Reduce the amount of calls to Stage::GetCurrent() in actor creation and remove depend... 71/35571/2
authorKimmo Hoikka <kimmo.hoikka@samsung.com>
Wed, 18 Feb 2015 11:43:50 +0000 (11:43 +0000)
committerKimmo Hoikka <kimmo.hoikka@samsung.com>
Wed, 18 Feb 2015 13:01:58 +0000 (13:01 +0000)
Removes 143 calls to Stage::GetCurrent from dali-demo startup

Change-Id: If410caf76900d165bafb4abb996fd655cfce0acf

dali/internal/event/actors/actor-impl.cpp
dali/internal/event/common/stage-impl.cpp
dali/internal/event/common/stage-impl.h
dali/internal/event/common/thread-local-storage.cpp
dali/internal/event/common/thread-local-storage.h
dali/public-api/common/stage.cpp
dali/public-api/object/base-object.cpp

index b6a3ea4..ffcd668 100644 (file)
@@ -2086,6 +2086,7 @@ Actor::Actor( DerivedType derivedType )
 void Actor::Initialize()
 {
   mStage = Stage::GetCurrent();
+  DALI_ASSERT_ALWAYS( mStage && "Stage doesn't exist" );
 
   // Node creation
   SceneGraph::Node* node = CreateNode();
@@ -2095,7 +2096,7 @@ void Actor::Initialize()
 
   OnInitialize();
 
-  RegisterObject();
+  mStage->RegisterObject( this );
 }
 
 Actor::~Actor()
@@ -2122,7 +2123,7 @@ Actor::~Actor()
       mNode = NULL; // Node is about to be destroyed
     }
 
-    UnregisterObject();
+    mStage->UnregisterObject( this );
   }
 
 #ifdef DYNAMICS_SUPPORT
index 0e5130a..02572bd 100644 (file)
@@ -110,7 +110,14 @@ void Stage::Uninitialize()
 
 StagePtr Stage::GetCurrent()
 {
-  return ThreadLocalStorage::Get().GetCurrentStage();
+  StagePtr stage( NULL );
+  // no checking in this version
+  ThreadLocalStorage* tls = ThreadLocalStorage::GetInternal();
+  if( tls )
+  {
+    stage = tls->GetCurrentStage();
+  }
+  return stage;
 }
 
 bool Stage::IsInstalled()
@@ -123,6 +130,16 @@ ObjectRegistry& Stage::GetObjectRegistry()
   return *mObjectRegistry;
 }
 
+void Stage::RegisterObject( Dali::BaseObject* object )
+{
+  mObjectRegistry->RegisterObject( object );
+}
+
+void Stage::UnregisterObject( Dali::BaseObject* object )
+{
+  mObjectRegistry->UnregisterObject( object );
+}
+
 Layer& Stage::GetRootActor()
 {
   return *mRootLayer;
index 3a9bd85..03d4d93 100644 (file)
@@ -98,6 +98,7 @@ public:
 
   /**
    * @copydoc Dali::Stage::GetCurrent()
+   * @note this version is for internal usage so it does not assert
    */
   static StagePtr GetCurrent();
 
@@ -112,6 +113,16 @@ public:
   ObjectRegistry& GetObjectRegistry();
 
   /**
+   * @copydoc Dali::Internal::ObjectRegistry::RegisterObject
+   */
+  void RegisterObject( Dali::BaseObject* object );
+
+  /**
+   * @copydoc Dali::Internal::ObjectRegistry::UnregisterObject
+   */
+  void UnregisterObject( Dali::BaseObject* object );
+
+  /**
    * Retrieve the root actor (not publically accessible).
    * @return The root actor.
    */
index f1f69cf..e46ea9a 100644 (file)
 // CLASS HEADER
 #include <dali/internal/event/common/thread-local-storage.h>
 
-// EXTERNAL INCLUDES
-#include <boost/thread/tss.hpp>
-#include <memory>
-
 // INTERNAL INCLUDES
 #include <dali/internal/common/core-impl.h>
-#include <dali/internal/update/manager/update-manager.h>
-#include <dali/internal/render/common/render-manager.h>
-#include <dali/integration-api/platform-abstraction.h>
 #include <dali/public-api/common/dali-common.h>
-#include <dali/public-api/math/vector2.h>
 
 namespace Dali
 {
@@ -38,21 +30,16 @@ namespace Internal
 
 namespace
 {
-#ifdef EMSCRIPTEN
-  std::auto_ptr<ThreadLocalStorage> threadLocal;
-#else
-  boost::thread_specific_ptr<ThreadLocalStorage> threadLocal;
-#endif
+__thread ThreadLocalStorage* threadLocal = NULL;
 }
 
 ThreadLocalStorage::ThreadLocalStorage(Core* core)
 : mCore(core)
 {
-  DALI_ASSERT_ALWAYS( threadLocal.get() == NULL && "Cannot create more than one ThreadLocalStorage object" );
+  DALI_ASSERT_ALWAYS( threadLocal == NULL && "Cannot create more than one ThreadLocalStorage object" );
 
   // reset is used to store a new value associated with this thread
-  threadLocal.reset(this);
-
+  threadLocal = this;
 }
 
 ThreadLocalStorage::~ThreadLocalStorage()
@@ -61,22 +48,25 @@ ThreadLocalStorage::~ThreadLocalStorage()
 
 void ThreadLocalStorage::Remove()
 {
-  threadLocal.reset();
+  threadLocal = NULL;
 }
 
 ThreadLocalStorage& ThreadLocalStorage::Get()
 {
-  ThreadLocalStorage* tls = threadLocal.get();
-
-  DALI_ASSERT_ALWAYS(tls);
+  DALI_ASSERT_ALWAYS(threadLocal);
 
-  return *tls;
+  return *threadLocal;
 }
 
 bool ThreadLocalStorage::Created()
 {
   // see if the TLS has been set yet
-  return (threadLocal.get() != NULL);
+  return (threadLocal != NULL);
+}
+
+ThreadLocalStorage* ThreadLocalStorage::GetInternal()
+{
+  return threadLocal;
 }
 
 Dali::Integration::PlatformAbstraction& ThreadLocalStorage::GetPlatformAbstraction()
index f0dff0c..c6bf41a 100644 (file)
@@ -90,6 +90,12 @@ public:
   static bool Created();
 
   /**
+   * Get a pointer to the TLS or NULL if not initialized
+   * @return pointer to the TLS
+   */
+  static ThreadLocalStorage* GetInternal();
+
+  /**
    * get platform abstraction
    * @return reference to core
    */
index b47f7ea..5e2b0f9 100644 (file)
@@ -73,7 +73,9 @@ Stage::Stage(Internal::Stage* internal)
 
 Stage Stage::GetCurrent()
 {
-  return Stage(Internal::Stage::GetCurrent());
+  Internal::Stage* stage = Internal::Stage::GetCurrent();
+  DALI_ASSERT_ALWAYS( stage && "Stage doesn't exist" );
+  return Stage( stage );
 }
 
 bool Stage::IsInstalled()
index 43f4c29..d6f5793 100644 (file)
@@ -38,18 +38,20 @@ BaseObject::~BaseObject()
 
 void BaseObject::RegisterObject()
 {
-  if( Internal::Stage::IsInstalled() )
+  Internal::Stage* stage = Internal::Stage::GetCurrent();
+  if( stage )
   {
-    Internal::Stage::GetCurrent()->GetObjectRegistry().RegisterObject( this );
+    stage->RegisterObject( this );
   }
 }
 
 void BaseObject::UnregisterObject()
 {
   // Guard to allow handle destruction after Core has been destroyed
-  if( Internal::Stage::IsInstalled() )
+  Internal::Stage* stage = Internal::Stage::GetCurrent();
+  if( stage )
   {
-    Internal::Stage::GetCurrent()->GetObjectRegistry().UnregisterObject( this );
+    stage->UnregisterObject( this );
   }
 }