[workqueue] Reduce critical section, improve performance

This commit is contained in:
guozhanxin 2023-02-16 20:19:26 +08:00 committed by Man, Jianting (Meco)
parent bc385cd55c
commit b065486b23
1 changed files with 8 additions and 16 deletions

View File

@ -93,30 +93,22 @@ static rt_err_t _workqueue_submit_work(struct rt_workqueue *queue,
struct rt_work *work, rt_tick_t ticks) struct rt_work *work, rt_tick_t ticks)
{ {
rt_base_t level; rt_base_t level;
rt_err_t err;
level = rt_hw_interrupt_disable(); level = rt_hw_interrupt_disable();
/* remove list */ /* remove list */
rt_list_remove(&(work->list)); rt_list_remove(&(work->list));
work->flags &= ~RT_WORK_STATE_PENDING; work->flags &= ~RT_WORK_STATE_PENDING;
if (ticks == 0) if (ticks == 0)
{ {
if (queue->work_current != work) rt_list_insert_after(queue->work_list.prev, &(work->list));
{ work->flags |= RT_WORK_STATE_PENDING;
rt_list_insert_after(queue->work_list.prev, &(work->list)); work->workqueue = queue;
work->flags |= RT_WORK_STATE_PENDING;
work->workqueue = queue;
err = RT_EOK;
}
else
{
err = -RT_EBUSY;
}
/* whether the workqueue is doing work */ /* whether the workqueue is doing work */
if (queue->work_current == RT_NULL && 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 */ /* resume work thread */
rt_thread_resume(queue->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); rt_hw_interrupt_enable(level);
} }
return err; return RT_EOK;
} }
else if (ticks < RT_TICK_MAX / 2) 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 */ /* whether the workqueue is doing work */
if (queue->work_current == RT_NULL && 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 */ /* resume work thread */
rt_thread_resume(queue->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)); rt_list_insert_after(&queue->work_list, &(work->list));
/* whether the workqueue is doing work */ /* whether the workqueue is doing work */
if (queue->work_current == RT_NULL && 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 */ /* resume work thread */
rt_thread_resume(queue->work_thread); rt_thread_resume(queue->work_thread);