void Actor::Initialize()
{
mStage = Stage::GetCurrent();
+ DALI_ASSERT_ALWAYS( mStage && "Stage doesn't exist" );
// Node creation
SceneGraph::Node* node = CreateNode();
OnInitialize();
- RegisterObject();
+ mStage->RegisterObject( this );
}
Actor::~Actor()
mNode = NULL; // Node is about to be destroyed
}
- UnregisterObject();
+ mStage->UnregisterObject( this );
}
#ifdef DYNAMICS_SUPPORT
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()
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;
/**
* @copydoc Dali::Stage::GetCurrent()
+ * @note this version is for internal usage so it does not assert
*/
static StagePtr GetCurrent();
*/
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.
// 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
{
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()
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()
*/
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
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()
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 );
}
}