Do not running same tasks at multiple threads. 07/302407/2
authorEunki, Hong <eunkiki.hong@samsung.com>
Wed, 6 Dec 2023 07:49:34 +0000 (16:49 +0900)
committerEunki Hong <eunkiki.hong@samsung.com>
Fri, 8 Dec 2023 02:07:27 +0000 (02:07 +0000)
Let we make to do not execute same tasks at multiple threads
at the same timing.

It will make sure that we can control AsyncTask::Process API works
more thread-safety.

Change-Id: I5986c4a683a61ba03b2737d201fc5e7d602fc9de
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
dali/internal/system/common/async-task-manager-impl.cpp

index b23a24f..1fdb733 100644 (file)
@@ -1003,6 +1003,22 @@ AsyncTaskPtr AsyncTaskManager::PopNextTaskToProcess()
         taskAvaliable = (mAvaliableLowPriorityTaskCounts > 0u); // priority is low, but we can use it.
       }
 
+      // Check whether we try to running same task at multiple threads.
+      if(taskAvaliable)
+      {
+        Mutex::ScopedLock lock(mRunningTasksMutex); // We can lock this mutex under mWaitingTasksMutex.
+        auto              mapIter = mCacheImpl->mRunningTasksCache.find((*iter).Get());
+        if(mapIter != mCacheImpl->mRunningTasksCache.end())
+        {
+          if(!mapIter->second.empty())
+          {
+            // Some other thread running this tasks now. Ignore it.
+            DALI_LOG_INFO(gAsyncTasksManagerLogFilter, Debug::Verbose, "Some other thread running this task [%p]\n", (*iter).Get());
+            taskAvaliable = false;
+          }
+        }
+      }
+
       if(taskAvaliable)
       {
         nextTask = *iter;