Description: fix async work task crash issue

IssueNo: I4CGY3
Feature or Bugfix: Feature
Binary Source:No

Signed-off-by: jiadexiang <jiadexiang@huawei.com>
This commit is contained in:
jiadexiang
2021-10-14 11:24:55 +08:00
parent 033b4c678e
commit a249c7e20e
3 changed files with 5 additions and 4 deletions
@@ -98,6 +98,7 @@ void AsyncTaskManager::Callback()
while (head_ != nullptr) {
AsyncTask *task = head_;
task->isRunning = true;
task->handler(task->data);
if (head_ == tail_) {
tail_ = nullptr;
@@ -129,6 +130,7 @@ uint16_t AsyncTaskManager::Dispatch(AsyncTaskHandler handler, void *data, const
task->data = data;
task->id = (++uniqueTaskID_);
task->context = context;
task->isRunning = false;
task->next = nullptr;
if (head_ == nullptr) {
head_ = task;
@@ -151,7 +153,7 @@ void AsyncTaskManager::Cancel(uint16_t taskID)
AsyncTask *node = head_;
AsyncTask *prev = nullptr;
while (node != nullptr) {
if (node->id == taskID) {
if (node->id == taskID && !(node->isRunning)) {
if (prev == nullptr) {
head_ = head_->next;
} else {
@@ -182,7 +184,7 @@ void AsyncTaskManager::CancelWithContext(const void *context)
AsyncTask *next = nullptr;
while (node != nullptr) {
next = node->next;
if (node->context == context) {
if ((node->context == context) && !(node->isRunning)) {
if (prev == nullptr) {
head_ = head_->next;
} else {
@@ -36,6 +36,7 @@ struct AsyncTask final : public MemoryHeap {
AsyncTaskHandler handler;
void *data;
AsyncTask *next;
bool isRunning;
};
constexpr uint16_t DISPATCH_FAILURE = 0;
@@ -181,8 +181,6 @@ INCLUDEPATH += \
$${ROOT_PATH}/foundation/aafwk/aafwk_lite/interfaces/kits/ability_lite \
$${ROOT_PATH}/foundation/aafwk/aafwk_lite/interfaces/kits/want_lite \
$${ROOT_PATH}/foundation/aafwk/aafwk_lite/interfaces/innerkits/abilitymgr_lite \
$${ROOT_PATH}/foundation/appexecfwk/appexecfwk_lite/interfaces/kits/bundle_lite \
$${ROOT_PATH}/foundation/appexecfwk/appexecfwk_lite/utils/bundle_lite \
$${ROOT_PATH}/foundation/communication/ipc_lite/liteipc/include \
$${ROOT_PATH}/third_party/bounds_checking_function/include \
$${ROOT_PATH}/foundation/ace/ace_engine_lite/interfaces/innerkits/builtin/async \