Add mutex to the Adaptor 36/266336/2
authorHeeyong Song <heeyong.song@samsung.com>
Wed, 10 Nov 2021 15:25:21 +0000 (00:25 +0900)
committerHeeyong Song <heeyong.song@samsung.com>
Tue, 16 Nov 2021 05:09:37 +0000 (05:09 +0000)
Prevent the main thread and the update thread from accessing the
mWindows at the same time

Change-Id: I3ab8e9565b37165451468771d89967493a27985b

dali/internal/adaptor/common/adaptor-impl.cpp
dali/internal/adaptor/common/adaptor-impl.h

index feac31b..d880a94 100644 (file)
@@ -295,7 +295,6 @@ void Adaptor::Initialize(GraphicsFactory& graphicsFactory)
     Integration::SetTapMaximumAllowedTime(mEnvironmentOptions->GetTapMaximumAllowedTime());
   }
 
-
   std::string systemCachePath = GetSystemCachePath();
   if(!systemCachePath.empty())
   {
@@ -675,7 +674,10 @@ bool Adaptor::AddWindow(Dali::Integration::SceneHolder childWindow)
   windowImpl.GetRootLayer().SetProperty(Dali::Actor::Property::LAYOUT_DIRECTION, mRootLayoutDirection);
 
   // Add the new Window to the container - the order is not important
-  mWindows.push_back(&windowImpl);
+  {
+    Dali::Mutex::ScopedLock lock(mMutex);
+    mWindows.push_back(&windowImpl);
+  }
 
   Dali::RenderSurfaceInterface* surface = windowImpl.GetSurface();
 
@@ -693,6 +695,7 @@ bool Adaptor::RemoveWindow(Dali::Integration::SceneHolder* childWindow)
   {
     if(*iter == &windowImpl)
     {
+      Dali::Mutex::ScopedLock lock(mMutex);
       mWindows.erase(iter);
       return true;
     }
@@ -707,6 +710,7 @@ bool Adaptor::RemoveWindow(std::string childWindowName)
   {
     if((*iter)->GetName() == childWindowName)
     {
+      Dali::Mutex::ScopedLock lock(mMutex);
       mWindows.erase(iter);
       return true;
     }
@@ -721,6 +725,7 @@ bool Adaptor::RemoveWindow(Internal::Adaptor::SceneHolder* childWindow)
   {
     if((*iter)->GetId() == childWindow->GetId())
     {
+      Dali::Mutex::ScopedLock lock(mMutex);
       mWindows.erase(iter);
       return true;
     }
@@ -815,6 +820,7 @@ Integration::PlatformAbstraction& Adaptor::GetPlatformAbstraction() const
 
 void Adaptor::GetWindowContainerInterface(WindowContainer& windows)
 {
+  Dali::Mutex::ScopedLock lock(mMutex);
   windows = mWindows;
 }
 
@@ -1221,6 +1227,7 @@ Adaptor::Adaptor(Dali::Integration::SceneHolder window, Dali::Adaptor& adaptor,
   mSystemTracer(),
   mObjectProfiler(nullptr),
   mSocketFactory(),
+  mMutex(),
   mThreadMode(threadMode),
   mEnvironmentOptionsOwned(environmentOptions ? false : true /* If not provided then we own the object */),
   mUseRemoteSurface(false),
index 331ab9a..69a6b3f 100644 (file)
@@ -19,6 +19,7 @@
  */
 
 // EXTERNAL INCLUDES
+#include <dali/devel-api/threading/mutex.h>
 #include <dali/integration-api/render-controller.h>
 #include <dali/public-api/common/vector-wrapper.h>
 #include <dali/public-api/math/rect.h>
@@ -679,6 +680,7 @@ private:                                          // Data
   SystemTrace                 mSystemTracer;                          ///< System tracer
   ObjectProfiler*             mObjectProfiler;                        ///< Tracks object lifetime for profiling
   SocketFactory               mSocketFactory;                         ///< Socket factory
+  Mutex                       mMutex;                                 ///< Mutex
   ThreadMode                  mThreadMode;                            ///< The thread mode
   const bool                  mEnvironmentOptionsOwned : 1;           ///< Whether we own the EnvironmentOptions (and thus, need to delete it)
   bool                        mUseRemoteSurface : 1;                  ///< whether the remoteSurface is used or not