When AsyncTaskManager use other thread, no need to wake up main thread.
Change-Id: I2b4dfb797e0981002776b345b43f988dd5eb83f9
/*
- * 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.
void AsyncTaskManager::CompleteTask(AsyncTaskPtr task)
{
// Lock while adding task to the queue
- Mutex::ScopedLock lock(mMutex);
- for(auto iter = mRunningTasks.begin(), endIter = mRunningTasks.end(); iter != endIter; ++iter)
{
- if((*iter).first == task)
+ Mutex::ScopedLock lock(mMutex);
+ for(auto iter = mRunningTasks.begin(), endIter = mRunningTasks.end(); iter != endIter; ++iter)
{
- if(!(*iter).second)
+ if((*iter).first == task)
{
- mCompletedTasks.push_back(task);
- }
+ if(!(*iter).second)
+ {
+ if(task->GetCallbackInvocationThread() == AsyncTask::ThreadType::MAIN_THREAD)
+ {
+ mCompletedTasks.push_back(task);
+ }
+ }
- // Delete this task in running queue
- mRunningTasks.erase(iter);
- break;
+ // Delete this task in running queue
+ mRunningTasks.erase(iter);
+ break;
+ }
}
}
// wake up the main thread
- mTrigger->Trigger();
+ if(task->GetCallbackInvocationThread() == AsyncTask::ThreadType::MAIN_THREAD)
+ {
+ mTrigger->Trigger();
+ }
+ else
+ {
+ CallbackBase::Execute(*(task->GetCompletedCallback()), task);
+ }
}
void AsyncTaskManager::UnregisterProcessor()
/*
- * 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.
namespace Dali
{
-
-AsyncTask::AsyncTask(CallbackBase* callback)
-: mCompletedCallback(std::unique_ptr<CallbackBase>(callback))
+AsyncTask::AsyncTask(CallbackBase* callback, ThreadType threadType)
+: mCompletedCallback(std::unique_ptr<CallbackBase>(callback)),
+ mThreadType(threadType)
{
}
return mCompletedCallback.get();
}
+AsyncTask::ThreadType AsyncTask::GetCallbackInvocationThread()
+{
+ return mThreadType;
+}
+
AsyncTaskManager::AsyncTaskManager() = default;
AsyncTaskManager::~AsyncTaskManager() = default;
#define DALI_ASYNC_TASK_MANAGER_H
/*
- * 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.
class DALI_ADAPTOR_API AsyncTask : public RefObject
{
public:
+ // The Type of invocation thread
+ enum class ThreadType
+ {
+ MAIN_THREAD,
+ WORKER_THREAD
+ };
+
/**
* Constructor
* @SINCE_2_2.3
- * @param[in] callback The callback to up the main thread. The ownership of callback is taken by this class
+ * @param[in] callback The callback to invoke on task completion, either on the main thread on the worker thread. The ownership of callback is taken by this class.
+ * @param[in] threadType The thread type of invocation callback.
*/
- AsyncTask(CallbackBase* callback);
+ AsyncTask(CallbackBase* callback, ThreadType threadType = AsyncTask::ThreadType::MAIN_THREAD);
/**
* Get the complated callback
CallbackBase* GetCompletedCallback();
/**
+ * Get the thread of the invocation callback
+ * @SINCE_2_2.9
+ * @return the type of invocation callback.
+ */
+ ThreadType GetCallbackInvocationThread();
+
+ /**
* Destructor.
* @SINCE_2_2.3
*/
private:
std::unique_ptr<CallbackBase> mCompletedCallback;
+ ThreadType mThreadType;
// Undefined
AsyncTask(const AsyncTask& task) = delete;