From bc77d73b54827fbf987b99dc14682be607401f94 Mon Sep 17 00:00:00 2001 From: Heeyong Song Date: Tue, 27 Dec 2022 16:06:52 +0900 Subject: [PATCH] Make assertion when SetParent is not called on the main thread Change-Id: Ia224a99b7760f2ab2ec6e19700faa2e84091ce1a --- dali/internal/event/actors/actor-impl.cpp | 6 +++--- dali/internal/event/common/event-thread-services.cpp | 7 ++++++- dali/internal/event/common/event-thread-services.h | 11 ++++++++++- dali/internal/event/common/thread-local-storage.cpp | 18 +++++++++++++----- dali/internal/event/common/thread-local-storage.h | 9 ++++++++- 5 files changed, 40 insertions(+), 11 deletions(-) diff --git a/dali/internal/event/actors/actor-impl.cpp b/dali/internal/event/actors/actor-impl.cpp index bf91a94..ab20929 100644 --- a/dali/internal/event/actors/actor-impl.cpp +++ b/dali/internal/event/actors/actor-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 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. @@ -1481,7 +1481,7 @@ void Actor::SetParent(ActorParent* parent, bool notify) Actor* parentActor = static_cast(parent); mScene = parentActor->mScene; - if(EventThreadServices::IsCoreRunning() && // Don't emit signals or send messages during Core destruction + if(!EventThreadServices::IsShuttingDown() && // Don't emit signals or send messages during Core destruction parentActor->OnScene()) { // Instruct each actor to create a corresponding node in the scene graph @@ -1497,7 +1497,7 @@ void Actor::SetParent(ActorParent* parent, bool notify) mParent = nullptr; - if(EventThreadServices::IsCoreRunning() && // Don't emit signals or send messages during Core destruction + if(!EventThreadServices::IsShuttingDown() && // Don't emit signals or send messages during Core destruction OnScene()) { // Disconnect the Node & its children from the scene-graph. diff --git a/dali/internal/event/common/event-thread-services.cpp b/dali/internal/event/common/event-thread-services.cpp index 75b6c8a..87a42a8 100644 --- a/dali/internal/event/common/event-thread-services.cpp +++ b/dali/internal/event/common/event-thread-services.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 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. @@ -34,5 +34,10 @@ bool EventThreadServices::IsCoreRunning() return ThreadLocalStorage::Created(); } +bool EventThreadServices::IsShuttingDown() +{ + return ThreadLocalStorage::IsShuttingDown(); +} + } // namespace Internal } // namespace Dali diff --git a/dali/internal/event/common/event-thread-services.h b/dali/internal/event/common/event-thread-services.h index 494a722..f2c6ae7 100644 --- a/dali/internal/event/common/event-thread-services.h +++ b/dali/internal/event/common/event-thread-services.h @@ -2,7 +2,7 @@ #define DALI_INTERNAL_EVENT_THREAD_SERVICES_H /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 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. @@ -116,8 +116,17 @@ public: /** * @return true if core is still running and we can send messages + * @note It returns false if it is called from a thread other than the main thread. */ static bool IsCoreRunning(); + + /** + * @brief Check if the event thread service is shutting down. + * + * @return true if the event thread service is shutting down. + * @note It returns false if the core hasn't been initialised yet. + */ + static bool IsShuttingDown(); }; } // namespace Internal diff --git a/dali/internal/event/common/thread-local-storage.cpp b/dali/internal/event/common/thread-local-storage.cpp index 6ebfc68..86e848d 100644 --- a/dali/internal/event/common/thread-local-storage.cpp +++ b/dali/internal/event/common/thread-local-storage.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 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. @@ -51,22 +51,25 @@ namespace Internal { namespace { -thread_local ThreadLocalStorage* threadLocal = nullptr; -} +thread_local ThreadLocalStorage* threadLocal = nullptr; +thread_local bool isShuttingDown = false; +} // namespace ThreadLocalStorage::ThreadLocalStorage(Core* core) : mCore(core) { DALI_ASSERT_ALWAYS(threadLocal == nullptr && "Cannot create more than one ThreadLocalStorage object"); - threadLocal = this; + threadLocal = this; + isShuttingDown = false; } ThreadLocalStorage::~ThreadLocalStorage() = default; void ThreadLocalStorage::Remove() { - threadLocal = nullptr; + threadLocal = nullptr; + isShuttingDown = true; } ThreadLocalStorage& ThreadLocalStorage::Get() @@ -92,6 +95,11 @@ bool ThreadLocalStorage::Created() return (threadLocal != nullptr); } +bool ThreadLocalStorage::IsShuttingDown() +{ + return isShuttingDown; +} + ThreadLocalStorage* ThreadLocalStorage::GetInternal() { return threadLocal; diff --git a/dali/internal/event/common/thread-local-storage.h b/dali/internal/event/common/thread-local-storage.h index 16f3876..8baef7d 100644 --- a/dali/internal/event/common/thread-local-storage.h +++ b/dali/internal/event/common/thread-local-storage.h @@ -2,7 +2,7 @@ #define DALI_INTERNAL_THREAD_LOCAL_STORAGE_H /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 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. @@ -90,6 +90,13 @@ public: static bool Created(); /** + * Checks if the system is shutting down + * @return true if the system is shutting down + * @note It returns false if the core hasn't been initialised yet. + */ + static bool IsShuttingDown(); + + /** * Get a pointer to the TLS or NULL if not initialized * @return pointer to the TLS */ -- 2.7.4