提交 b065486b 编写于 作者: G guozhanxin 提交者: mysterywolf

[workqueue] Reduce critical section, improve performance

上级 bc385cd5
...@@ -93,30 +93,22 @@ static rt_err_t _workqueue_submit_work(struct rt_workqueue *queue, ...@@ -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)); rt_list_insert_after(queue->work_list.prev, &(work->list));
work->flags |= RT_WORK_STATE_PENDING; work->flags |= RT_WORK_STATE_PENDING;
work->workqueue = queue; 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, ...@@ -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) ...@@ -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 ...@@ -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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册