From b065486b23bd9c2cd8d9e58e4daac3fb47dea7ed Mon Sep 17 00:00:00 2001 From: guozhanxin Date: Thu, 16 Feb 2023 20:19:26 +0800 Subject: [PATCH] [workqueue] Reduce critical section, improve performance --- components/drivers/ipc/workqueue.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/components/drivers/ipc/workqueue.c b/components/drivers/ipc/workqueue.c index d9b98929c8..c70a1e1e28 100644 --- a/components/drivers/ipc/workqueue.c +++ b/components/drivers/ipc/workqueue.c @@ -93,30 +93,22 @@ static rt_err_t _workqueue_submit_work(struct rt_workqueue *queue, struct rt_work *work, rt_tick_t ticks) { rt_base_t level; - rt_err_t err; level = rt_hw_interrupt_disable(); + /* remove list */ rt_list_remove(&(work->list)); work->flags &= ~RT_WORK_STATE_PENDING; if (ticks == 0) { - if (queue->work_current != work) - { - rt_list_insert_after(queue->work_list.prev, &(work->list)); - work->flags |= RT_WORK_STATE_PENDING; - work->workqueue = queue; - err = RT_EOK; - } - else - { - err = -RT_EBUSY; - } + rt_list_insert_after(queue->work_list.prev, &(work->list)); + work->flags |= RT_WORK_STATE_PENDING; + work->workqueue = queue; /* whether the workqueue is doing work */ if (queue->work_current == RT_NULL && - ((queue->work_thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_STAT_MASK)) + ((queue->work_thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_SUSPEND)) { /* resume work thread */ rt_thread_resume(queue->work_thread); @@ -127,7 +119,7 @@ static rt_err_t _workqueue_submit_work(struct rt_workqueue *queue, { rt_hw_interrupt_enable(level); } - return err; + return RT_EOK; } else if (ticks < RT_TICK_MAX / 2) { @@ -198,7 +190,7 @@ static void _delayed_work_timeout_handler(void *parameter) } /* whether the workqueue is doing work */ if (queue->work_current == RT_NULL && - ((queue->work_thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_STAT_MASK)) + ((queue->work_thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_SUSPEND)) { /* resume work thread */ rt_thread_resume(queue->work_thread); @@ -356,7 +348,7 @@ rt_err_t rt_workqueue_urgent_work(struct rt_workqueue *queue, struct rt_work *wo rt_list_insert_after(&queue->work_list, &(work->list)); /* whether the workqueue is doing work */ if (queue->work_current == RT_NULL && - ((queue->work_thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_STAT_MASK)) + ((queue->work_thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_SUSPEND)) { /* resume work thread */ rt_thread_resume(queue->work_thread);