summaryrefslogtreecommitdiff
path: root/components/drivers
diff options
context:
space:
mode:
authortangyuxin <[email protected]>2021-01-30 18:29:17 +0800
committertangyuxin <[email protected]>2021-02-01 15:02:17 +0800
commit10b5aa8f59fa83f4f053fd2318cf5268544b3304 (patch)
treeba251ff4ec3f118a31a04f04255cd7b7608d1a1b /components/drivers
parent0c87becb3eed0e890198740589f0db94ab6256cf (diff)
合并 cancel 和 cancel_delayed 函数,优化代码体积
合并 _workqueue_cancel_work 和 _workqueue_cancel_delayed_work 函数,优化代码体积
Diffstat (limited to 'components/drivers')
-rw-r--r--components/drivers/src/workqueue.c58
1 files changed, 9 insertions, 49 deletions
diff --git a/components/drivers/src/workqueue.c b/components/drivers/src/workqueue.c
index 557f349e53..0c3c0e9f53 100644
--- a/components/drivers/src/workqueue.c
+++ b/components/drivers/src/workqueue.c
@@ -143,63 +143,23 @@ static rt_err_t _workqueue_submit_work(struct rt_workqueue *queue,
return -RT_ERROR;
}
-static rt_err_t _workqueue_cancel_work(struct rt_workqueue *queue, struct rt_work *work)
+static rt_err_t _workqueue_cancel_work(struct rt_work *work)
{
rt_base_t level;
level = rt_hw_interrupt_disable();
- if (queue->work_current == work)
- {
- rt_hw_interrupt_enable(level);
- return -RT_EBUSY;
- }
rt_list_remove(&(work->list));
work->flags &= ~RT_WORK_STATE_PENDING;
- rt_hw_interrupt_enable(level);
-
- return RT_EOK;
-}
-
-static rt_err_t _workqueue_cancel_delayed_work(struct rt_work *work)
-{
- rt_base_t level;
- int ret = RT_EOK;
-
- if (!work->workqueue)
- {
- ret = -EINVAL;
- goto __exit;
- }
-
- if (work->flags & RT_WORK_STATE_PENDING)
- {
- /* Remove from the queue if already submitted */
- ret = _workqueue_cancel_work(work->workqueue, work);
- if (ret)
- {
- goto __exit;
- }
- }
- else
+ /* Timer started */
+ if (work->flags & RT_WORK_STATE_SUBMITTING)
{
- if (work->flags & RT_WORK_STATE_SUBMITTING)
- {
- level = rt_hw_interrupt_disable();
- rt_timer_stop(&(work->timer));
- rt_timer_detach(&(work->timer));
- work->flags &= ~RT_WORK_STATE_SUBMITTING;
- rt_hw_interrupt_enable(level);
- }
+ rt_timer_stop(&(work->timer));
+ rt_timer_detach(&(work->timer));
+ work->flags &= ~RT_WORK_STATE_SUBMITTING;
}
-
- level = rt_hw_interrupt_disable();
- /* Detach from workqueue */
work->workqueue = RT_NULL;
- work->flags &= ~(RT_WORK_STATE_PENDING);
rt_hw_interrupt_enable(level);
-
-__exit:
- return ret;
+ return 0;
}
static void _delayed_work_timeout_handler(void *parameter)
@@ -317,11 +277,11 @@ rt_err_t rt_workqueue_cancel_work(struct rt_workqueue *queue, struct rt_work *wo
if (work->type & RT_WORK_TYPE_DELAYED)
{
- return _workqueue_cancel_delayed_work(work);
+ return _workqueue_cancel_work(work);
}
else
{
- return _workqueue_cancel_work(queue, work);
+ return _workqueue_cancel_work(work);
}
}