/*
- * 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.
mWorkingTasks(),
mSleepThread(MakeCallback(this, &VectorAnimationThread::OnAwakeFromSleep)),
mConditionalWait(),
+ mEventTriggerMutex(),
mNeedToSleep(false),
mDestroyThread(false),
mLogFactory(Dali::Adaptor::Get().GetLogFactory()),
// Stop the thread
{
ConditionalWait::ScopedLock lock(mConditionalWait);
- mDestroyThread = true;
- mNeedToSleep = false;
+ // Wait until some event thread trigger relative job finished.
+ {
+ Mutex::ScopedLock lock(mEventTriggerMutex);
+ mDestroyThread = true;
+ }
+ mNeedToSleep = false;
mConditionalWait.Notify(lock);
}
+ // Stop event trigger
+ mEventTrigger.reset();
+
DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "VectorAnimationThread::~VectorAnimationThread: Join [%p]\n", this);
Join();
void VectorAnimationThread::AddEventTriggerCallback(CallbackBase* callback)
{
- ConditionalWait::ScopedLock lock(mConditionalWait);
- mTriggerEventCallbacks.push_back(callback);
-
- if(!mEventTriggered)
+ Mutex::ScopedLock lock(mEventTriggerMutex);
+ if(!mDestroyThread)
{
- mEventTrigger->Trigger();
- mEventTriggered = true;
+ mTriggerEventCallbacks.push_back(callback);
+
+ if(!mEventTriggered)
+ {
+ mEventTrigger->Trigger();
+ mEventTriggered = true;
+ }
}
}
void VectorAnimationThread::RemoveEventTriggerCallbacks(CallbackBase* callback)
{
- ConditionalWait::ScopedLock lock(mConditionalWait);
- auto iter = std::remove(mTriggerEventCallbacks.begin(), mTriggerEventCallbacks.end(), callback);
- mTriggerEventCallbacks.erase(iter, mTriggerEventCallbacks.end());
+ Mutex::ScopedLock lock(mEventTriggerMutex);
+ if(!mDestroyThread)
+ {
+ auto iter = std::remove(mTriggerEventCallbacks.begin(), mTriggerEventCallbacks.end(), callback);
+ mTriggerEventCallbacks.erase(iter, mTriggerEventCallbacks.end());
+ }
}
void VectorAnimationThread::Run()
CallbackBase* VectorAnimationThread::GetNextEventCallback()
{
- ConditionalWait::ScopedLock lock(mConditionalWait);
-
- if(!mTriggerEventCallbacks.empty())
+ Mutex::ScopedLock lock(mEventTriggerMutex);
+ if(!mDestroyThread)
{
- auto iter = mTriggerEventCallbacks.begin();
- CallbackBase* callback = *iter;
- mTriggerEventCallbacks.erase(iter);
- return callback;
+ if(!mTriggerEventCallbacks.empty())
+ {
+ auto iter = mTriggerEventCallbacks.begin();
+ CallbackBase* callback = *iter;
+ mTriggerEventCallbacks.erase(iter);
+ return callback;
+ }
+ mEventTriggered = false;
}
- mEventTriggered = false;
return nullptr;
}
// EXTERNAL INCLUDES
#include <dali/devel-api/threading/conditional-wait.h>
+#include <dali/devel-api/threading/mutex.h>
#include <dali/devel-api/threading/thread.h>
#include <dali/integration-api/adaptor-framework/log-factory-interface.h>
#include <dali/integration-api/adaptor-framework/trace-factory-interface.h>
std::vector<CallbackBase*> mTriggerEventCallbacks{}; // Callbacks are not owned
SleepThread mSleepThread;
ConditionalWait mConditionalWait;
+ Mutex mEventTriggerMutex;
std::unique_ptr<EventThreadCallback> mEventTrigger{};
bool mNeedToSleep;
bool mDestroyThread;