mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-08-20 21:29:42 +08:00
🎈 perf: perf rt_hw_interrupt_disable/enable (#8042)
Signed-off-by: Shell <smokewood@qq.com> Co-authored-by: Shell <smokewood@qq.com>
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
* 2021-08-01 Meco Man remove rt_delayed_work_init()
|
||||
* 2021-08-14 Jackistang add comments for function interface
|
||||
* 2022-01-16 Meco Man add rt_work_urgent()
|
||||
* 2023-09-15 xqyjlj perf rt_hw_interrupt_disable/enable
|
||||
*/
|
||||
|
||||
#include <rthw.h>
|
||||
@@ -22,7 +23,6 @@ rt_inline rt_err_t _workqueue_work_completion(struct rt_workqueue *queue)
|
||||
{
|
||||
rt_err_t result;
|
||||
|
||||
rt_enter_critical();
|
||||
while (1)
|
||||
{
|
||||
/* try to take condition semaphore */
|
||||
@@ -44,7 +44,6 @@ rt_inline rt_err_t _workqueue_work_completion(struct rt_workqueue *queue)
|
||||
break;
|
||||
}
|
||||
}
|
||||
rt_exit_critical();
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -60,12 +59,12 @@ static void _workqueue_thread_entry(void *parameter)
|
||||
|
||||
while (1)
|
||||
{
|
||||
level = rt_hw_interrupt_disable();
|
||||
level = rt_spin_lock_irqsave(&(queue->spinlock));
|
||||
if (rt_list_isempty(&(queue->work_list)))
|
||||
{
|
||||
/* no software timer exist, suspend self. */
|
||||
rt_thread_suspend_with_flag(rt_thread_self(), RT_UNINTERRUPTIBLE);
|
||||
rt_hw_interrupt_enable(level);
|
||||
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
|
||||
rt_schedule();
|
||||
continue;
|
||||
}
|
||||
@@ -76,7 +75,7 @@ static void _workqueue_thread_entry(void *parameter)
|
||||
queue->work_current = work;
|
||||
work->flags &= ~RT_WORK_STATE_PENDING;
|
||||
work->workqueue = RT_NULL;
|
||||
rt_hw_interrupt_enable(level);
|
||||
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
|
||||
|
||||
/* do work */
|
||||
work->work_func(work, work->work_data);
|
||||
@@ -93,7 +92,7 @@ static rt_err_t _workqueue_submit_work(struct rt_workqueue *queue,
|
||||
{
|
||||
rt_base_t level;
|
||||
|
||||
level = rt_hw_interrupt_disable();
|
||||
level = rt_spin_lock_irqsave(&(queue->spinlock));
|
||||
|
||||
/* remove list */
|
||||
rt_list_remove(&(work->list));
|
||||
@@ -111,12 +110,12 @@ static rt_err_t _workqueue_submit_work(struct rt_workqueue *queue,
|
||||
{
|
||||
/* resume work thread */
|
||||
rt_thread_resume(queue->work_thread);
|
||||
rt_hw_interrupt_enable(level);
|
||||
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
|
||||
rt_schedule();
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_hw_interrupt_enable(level);
|
||||
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
|
||||
}
|
||||
return RT_EOK;
|
||||
}
|
||||
@@ -137,11 +136,11 @@ static rt_err_t _workqueue_submit_work(struct rt_workqueue *queue,
|
||||
work->workqueue = queue;
|
||||
/* insert delay work list */
|
||||
rt_list_insert_after(queue->delayed_list.prev, &(work->list));
|
||||
rt_hw_interrupt_enable(level);
|
||||
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
|
||||
rt_timer_start(&(work->timer));
|
||||
return RT_EOK;
|
||||
}
|
||||
rt_hw_interrupt_enable(level);
|
||||
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
|
||||
return -RT_ERROR;
|
||||
}
|
||||
|
||||
@@ -150,7 +149,7 @@ static rt_err_t _workqueue_cancel_work(struct rt_workqueue *queue, struct rt_wor
|
||||
rt_base_t level;
|
||||
rt_err_t err;
|
||||
|
||||
level = rt_hw_interrupt_disable();
|
||||
level = rt_spin_lock_irqsave(&(queue->spinlock));
|
||||
rt_list_remove(&(work->list));
|
||||
work->flags &= ~RT_WORK_STATE_PENDING;
|
||||
/* Timer started */
|
||||
@@ -162,7 +161,7 @@ static rt_err_t _workqueue_cancel_work(struct rt_workqueue *queue, struct rt_wor
|
||||
}
|
||||
err = queue->work_current != work ? RT_EOK : -RT_EBUSY;
|
||||
work->workqueue = RT_NULL;
|
||||
rt_hw_interrupt_enable(level);
|
||||
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -176,7 +175,7 @@ static void _delayed_work_timeout_handler(void *parameter)
|
||||
queue = work->workqueue;
|
||||
RT_ASSERT(queue != RT_NULL);
|
||||
|
||||
level = rt_hw_interrupt_disable();
|
||||
level = rt_spin_lock_irqsave(&(queue->spinlock));
|
||||
rt_timer_detach(&(work->timer));
|
||||
work->flags &= ~RT_WORK_STATE_SUBMITTING;
|
||||
/* remove delay list */
|
||||
@@ -193,12 +192,12 @@ static void _delayed_work_timeout_handler(void *parameter)
|
||||
{
|
||||
/* resume work thread */
|
||||
rt_thread_resume(queue->work_thread);
|
||||
rt_hw_interrupt_enable(level);
|
||||
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
|
||||
rt_schedule();
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_hw_interrupt_enable(level);
|
||||
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -258,6 +257,7 @@ struct rt_workqueue *rt_workqueue_create(const char *name, rt_uint16_t stack_siz
|
||||
return RT_NULL;
|
||||
}
|
||||
|
||||
rt_spin_lock_init(&(queue->spinlock));
|
||||
rt_thread_startup(queue->work_thread);
|
||||
}
|
||||
|
||||
@@ -341,7 +341,7 @@ rt_err_t rt_workqueue_urgent_work(struct rt_workqueue *queue, struct rt_work *wo
|
||||
RT_ASSERT(queue != RT_NULL);
|
||||
RT_ASSERT(work != RT_NULL);
|
||||
|
||||
level = rt_hw_interrupt_disable();
|
||||
level = rt_spin_lock_irqsave(&(queue->spinlock));
|
||||
/* NOTE: the work MUST be initialized firstly */
|
||||
rt_list_remove(&(work->list));
|
||||
rt_list_insert_after(&queue->work_list, &(work->list));
|
||||
@@ -351,12 +351,12 @@ rt_err_t rt_workqueue_urgent_work(struct rt_workqueue *queue, struct rt_work *wo
|
||||
{
|
||||
/* resume work thread */
|
||||
rt_thread_resume(queue->work_thread);
|
||||
rt_hw_interrupt_enable(level);
|
||||
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
|
||||
rt_schedule();
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_hw_interrupt_enable(level);
|
||||
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
|
||||
}
|
||||
|
||||
return RT_EOK;
|
||||
|
||||
Reference in New Issue
Block a user