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 b6a3ea4e9d501863fd98231f40a2191d72ae5e38..ffcd668464e4445cc6628fddc5e3079b3b5864b4 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 0e5130ad020c1f9b8f45473d359564a37b90d6fe..02572bd6448b3ef676bf208f1870680c157792df 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 3a9bd859f2a7b699bc5d95bf737d78d0d57c4d20..03d4d9306aa62c7d00eca7ebb50b26365f1b06d5 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();
 
@@ -111,6 +112,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 f1f69cfa43877700bbfeacbc8851025fe38b908c..e46ea9a0c6332df09757bf2fe534bd12dd8a3132 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 f0dff0c0246dc912e77bca2e8a9811b43052149b..c6bf41a6f933ec47a69606569aaff9eb36ec97c6 100644 (file)
@@ -89,6 +89,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 b47f7ea2e912f70f196c8f7dbcc406462765687d..5e2b0f904acd198f641869f06c2343d4c9c17cbb 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 43f4c29b129919cd39c803ebf60da1cdb39c8e58..d6f579372c2d724ae6b79e13a8140b485eaf3121 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 );
   }
 }