From d6b44ca52ed2ddc27e447ae2fe2914b9eb38687f Mon Sep 17 00:00:00 2001 From: tangyuxin <462747508@qq.com> Date: Sat, 6 Feb 2021 20:08:31 +0800 Subject: [PATCH] =?UTF-8?q?[workqueue]=20=E6=94=AF=E6=8C=81=E5=8F=96?= =?UTF-8?q?=E6=B6=88=E5=BB=B6=E6=97=B6=E5=B7=A5=E4=BD=9C=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/drivers/include/ipc/workqueue.h | 1 + components/drivers/src/workqueue.c | 21 +++++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/components/drivers/include/ipc/workqueue.h b/components/drivers/include/ipc/workqueue.h index 23e256c420..51976b4de7 100644 --- a/components/drivers/include/ipc/workqueue.h +++ b/components/drivers/include/ipc/workqueue.h @@ -29,6 +29,7 @@ enum struct rt_workqueue { rt_list_t work_list; + rt_list_t delayed_list; struct rt_work *work_current; /* current work */ struct rt_semaphore sem; diff --git a/components/drivers/src/workqueue.c b/components/drivers/src/workqueue.c index 1b7dbea0c1..eb6cefc006 100644 --- a/components/drivers/src/workqueue.c +++ b/components/drivers/src/workqueue.c @@ -135,6 +135,8 @@ static rt_err_t _workqueue_submit_work(struct rt_workqueue *queue, work->flags |= RT_WORK_STATE_SUBMITTING; } work->workqueue = queue; + /* insert delay work list */ + rt_list_insert_after(queue->delayed_list.prev, &(work->list)); rt_hw_interrupt_enable(level); rt_timer_start(&(work->timer)); return RT_EOK; @@ -175,6 +177,8 @@ static void _delayed_work_timeout_handler(void *parameter) level = rt_hw_interrupt_disable(); rt_timer_detach(&(work->timer)); work->flags &= ~RT_WORK_STATE_SUBMITTING; + /* remove delay list */ + rt_list_remove(&(work->list)); /* insert work queue */ if (queue->work_current != work) { @@ -205,6 +209,7 @@ struct rt_workqueue *rt_workqueue_create(const char *name, rt_uint16_t stack_siz { /* initialize work list */ rt_list_init(&(queue->work_list)); + rt_list_init(&(queue->delayed_list)); queue->work_current = RT_NULL; rt_sem_init(&(queue->sem), "wqueue", 0, RT_IPC_FLAG_FIFO); @@ -302,14 +307,22 @@ rt_err_t rt_workqueue_cancel_work_sync(struct rt_workqueue *queue, struct rt_wor rt_err_t rt_workqueue_cancel_all_work(struct rt_workqueue *queue) { struct rt_list_node *node, *next; + struct rt_work *work; + RT_ASSERT(queue != RT_NULL); - // TODO: cancel delay work + // cancel work rt_enter_critical(); - for (node = queue->work_list.next; node != &(queue->work_list); node = next) + while (rt_list_isempty(&queue->work_list) != RT_FALSE) { - next = node->next; - rt_list_remove(node); + work = rt_list_first_entry(&queue->work_list, struct rt_work, list); + _workqueue_cancel_work(work); + } + // cancel delay work + while (rt_list_isempty(&queue->delayed_list) != RT_FALSE) + { + work = rt_list_first_entry(&queue->delayed_list, struct rt_work, list); + _workqueue_cancel_work(work); } rt_exit_critical();