/*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 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.
#include <dali/devel-api/common/singleton-service.h>
#include <dali/integration-api/adaptor-framework/adaptor.h>
#include <dali/integration-api/debug.h>
-#include <dali/integration-api/trace.h>
#include <unordered_map>
uint32_t gThreadId = 0u; // Only for debug
#endif
-DALI_INIT_TRACE_FILTER(gTraceFilter, DALI_TRACE_PERFORMANCE_MARKER, false);
-
/**
* @brief Get the Task Name.
* Note that we can get const char* from std::string_view as data() since it will be const class.
else
{
DALI_LOG_INFO(gAsyncTasksManagerLogFilter, Debug::General, "Thread[%u] Process task [%p][%s]\n", threadId, task.Get(), GetTaskName(task));
- DALI_TRACE_BEGIN(gTraceFilter, GetTaskName(task));
task->Process();
- DALI_TRACE_END(gTraceFilter, GetTaskName(task));
DALI_LOG_INFO(gAsyncTasksManagerLogFilter, Debug::General, "Thread[%u] Complete task [%p][%s]\n", threadId, task.Get(), GetTaskName(task));
if(!mDestroyThread)
{
for(auto& iterator : mapIter->second)
{
DALI_ASSERT_DEBUG((*iterator) == task);
- if((*iterator)->GetPriorityType() == AsyncTask::PriorityType::HIGH)
+ if((*iterator)->GetPriorityType() == AsyncTask::PriorityType::HIGH && mWaitingHighProirityTaskCounts > 0u)
{
// Decrease the number of waiting tasks for high priority.
--mWaitingHighProirityTaskCounts;
}
}
- if(priorityType == AsyncTask::PriorityType::HIGH)
+ if(priorityType == AsyncTask::PriorityType::HIGH && mWaitingHighProirityTaskCounts > 0u)
{
// Decrease the number of waiting tasks for high priority.
--mWaitingHighProirityTaskCounts;
/// Worker thread called
void AsyncTaskManager::CompleteTask(AsyncTaskPtr&& task)
{
- bool notify = false;
-
if(task)
{
bool needTrigger = false;
- // Lock while check validation of task.
+ // Check now whether we need to execute callback or not, for worker thread cases.
+ if(task->GetCallbackInvocationThread() == AsyncTask::ThreadType::WORKER_THREAD)
{
- Mutex::ScopedLock lock(mRunningTasksMutex);
+ bool notify = false;
- auto mapIter = mCacheImpl->mRunningTasksCache.find(task.Get());
- if(mapIter != mCacheImpl->mRunningTasksCache.end())
+ // Lock while check validation of task.
{
- const auto cacheIter = mapIter->second.begin();
- DALI_ASSERT_ALWAYS(cacheIter != mapIter->second.end());
+ Mutex::ScopedLock lock(mRunningTasksMutex);
- const auto iter = *cacheIter;
- DALI_ASSERT_DEBUG(iter->first == task);
- if(iter->second == RunningTaskState::RUNNING)
+ auto mapIter = mCacheImpl->mRunningTasksCache.find(task.Get());
+ if(mapIter != mCacheImpl->mRunningTasksCache.end())
{
- // This task is valid.
- notify = true;
- }
- }
+ const auto cacheIter = mapIter->second.begin();
+ DALI_ASSERT_ALWAYS(cacheIter != mapIter->second.end());
- DALI_LOG_INFO(gAsyncTasksManagerLogFilter, Debug::Verbose, "CompleteTask [%p][%s] (is notify? : %d)\n", task.Get(), GetTaskName(task), notify);
- }
+ const auto iter = *cacheIter;
+ DALI_ASSERT_DEBUG(iter->first == task);
+ if(iter->second == RunningTaskState::RUNNING)
+ {
+ // This task is valid.
+ notify = true;
+ }
+ }
- // We should execute this tasks complete callback out of mutex
- if(notify && task->GetCallbackInvocationThread() == AsyncTask::ThreadType::WORKER_THREAD)
- {
- DALI_LOG_INFO(gAsyncTasksManagerLogFilter, Debug::Verbose, "Execute callback on worker thread [%p][%s]\n", task.Get(), GetTaskName(task));
- CallbackBase::Execute(*(task->GetCompletedCallback()), task);
+ DALI_LOG_INFO(gAsyncTasksManagerLogFilter, Debug::Verbose, "CompleteTask [%p][%s] (is notify? : %d)\n", task.Get(), GetTaskName(task), notify);
+ }
- // We need to remove task trace now.
- if(mTasksCompletedImpl->IsTasksCompletedCallbackExist())
+ // We should execute this tasks complete callback out of mutex
+ if(notify)
{
- mTasksCompletedImpl->RemoveTaskTrace(task);
+ DALI_LOG_INFO(gAsyncTasksManagerLogFilter, Debug::Verbose, "Execute callback on worker thread [%p][%s]\n", task.Get(), GetTaskName(task));
+ CallbackBase::Execute(*(task->GetCompletedCallback()), task);
- if(mTasksCompletedImpl->IsExecuteCallbackExist())
+ // We need to remove task trace now.
+ if(mTasksCompletedImpl->IsTasksCompletedCallbackExist())
{
- // We need to call EmitCompletedTasks(). Trigger main thread.
- needTrigger = true;
+ mTasksCompletedImpl->RemoveTaskTrace(task);
+
+ if(mTasksCompletedImpl->IsExecuteCallbackExist())
+ {
+ // We need to call EmitCompletedTasks(). Trigger main thread.
+ needTrigger = true;
+ }
}
}
}
// Lock while adding task to the queue
{
+ bool notify = false;
+
Mutex::ScopedLock lock(mRunningTasksMutex);
auto mapIter = mCacheImpl->mRunningTasksCache.find(task.Get());
const auto cacheIter = mapIter->second.begin();
DALI_ASSERT_ALWAYS(cacheIter != mapIter->second.end());
- const auto iter = *cacheIter;
+ const auto iter = *cacheIter;
+
+ DALI_ASSERT_DEBUG(iter->first == task);
+ if(iter->second == RunningTaskState::RUNNING)
+ {
+ // This task is valid.
+ notify = true;
+ }
+
const auto priorityType = iter->first->GetPriorityType();
// Increase avaliable task counts if it is low priority
if(priorityType == AsyncTask::PriorityType::LOW)