mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-09-22 11:30:01 +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:
@@ -7,6 +7,7 @@
|
||||
* Date Author Notes
|
||||
* 2012-09-30 Bernard first version.
|
||||
* 2021-08-18 chenyingchun add comments
|
||||
* 2023-09-15 xqyjlj perf rt_hw_interrupt_disable/enable
|
||||
*/
|
||||
|
||||
#include <rthw.h>
|
||||
@@ -25,10 +26,11 @@ void rt_completion_init(struct rt_completion *completion)
|
||||
rt_base_t level;
|
||||
RT_ASSERT(completion != RT_NULL);
|
||||
|
||||
level = rt_hw_interrupt_disable();
|
||||
rt_spin_lock_init(&(completion->spinlock));
|
||||
level = rt_spin_lock_irqsave(&(completion->spinlock));
|
||||
completion->flag = RT_UNCOMPLETED;
|
||||
rt_list_init(&completion->suspended_list);
|
||||
rt_hw_interrupt_enable(level);
|
||||
rt_spin_unlock_irqrestore(&(completion->spinlock), level);
|
||||
}
|
||||
RTM_EXPORT(rt_completion_init);
|
||||
|
||||
@@ -62,7 +64,7 @@ rt_err_t rt_completion_wait(struct rt_completion *completion,
|
||||
result = RT_EOK;
|
||||
thread = rt_thread_self();
|
||||
|
||||
level = rt_hw_interrupt_disable();
|
||||
level = rt_spin_lock_irqsave(&(completion->spinlock));
|
||||
if (completion->flag != RT_COMPLETED)
|
||||
{
|
||||
/* only one thread can suspend on complete */
|
||||
@@ -97,7 +99,7 @@ rt_err_t rt_completion_wait(struct rt_completion *completion,
|
||||
rt_timer_start(&(thread->thread_timer));
|
||||
}
|
||||
/* enable interrupt */
|
||||
rt_hw_interrupt_enable(level);
|
||||
rt_spin_unlock_irqrestore(&(completion->spinlock), level);
|
||||
|
||||
/* do schedule */
|
||||
rt_schedule();
|
||||
@@ -105,14 +107,14 @@ rt_err_t rt_completion_wait(struct rt_completion *completion,
|
||||
/* thread is waked up */
|
||||
result = thread->error;
|
||||
|
||||
level = rt_hw_interrupt_disable();
|
||||
level = rt_spin_lock_irqsave(&(completion->spinlock));
|
||||
}
|
||||
}
|
||||
/* clean completed flag */
|
||||
completion->flag = RT_UNCOMPLETED;
|
||||
|
||||
__exit:
|
||||
rt_hw_interrupt_enable(level);
|
||||
rt_spin_unlock_irqrestore(&(completion->spinlock), level);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -131,7 +133,7 @@ void rt_completion_done(struct rt_completion *completion)
|
||||
if (completion->flag == RT_COMPLETED)
|
||||
return;
|
||||
|
||||
level = rt_hw_interrupt_disable();
|
||||
level = rt_spin_lock_irqsave(&(completion->spinlock));
|
||||
completion->flag = RT_COMPLETED;
|
||||
|
||||
if (!rt_list_isempty(&(completion->suspended_list)))
|
||||
@@ -146,14 +148,14 @@ void rt_completion_done(struct rt_completion *completion)
|
||||
|
||||
/* resume it */
|
||||
rt_thread_resume(thread);
|
||||
rt_hw_interrupt_enable(level);
|
||||
rt_spin_unlock_irqrestore(&(completion->spinlock), level);
|
||||
|
||||
/* perform a schedule */
|
||||
rt_schedule();
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_hw_interrupt_enable(level);
|
||||
rt_spin_unlock_irqrestore(&(completion->spinlock), level);
|
||||
}
|
||||
}
|
||||
RTM_EXPORT(rt_completion_done);
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
* Date Author Notes
|
||||
* 2012-09-30 Bernard first version.
|
||||
* 2016-10-31 armink fix some resume push and pop thread bugs
|
||||
* 2023-09-15 xqyjlj perf rt_hw_interrupt_disable/enable
|
||||
*/
|
||||
|
||||
#include <rthw.h>
|
||||
@@ -57,6 +58,8 @@ rt_data_queue_init(struct rt_data_queue *queue,
|
||||
queue->is_empty = 1;
|
||||
queue->is_full = 0;
|
||||
|
||||
rt_spin_lock_init(&(queue->spinlock));
|
||||
|
||||
rt_list_init(&(queue->suspended_push_list));
|
||||
rt_list_init(&(queue->suspended_pop_list));
|
||||
|
||||
@@ -103,7 +106,7 @@ rt_err_t rt_data_queue_push(struct rt_data_queue *queue,
|
||||
result = RT_EOK;
|
||||
thread = rt_thread_self();
|
||||
|
||||
level = rt_hw_interrupt_disable();
|
||||
level = rt_spin_lock_irqsave(&(queue->spinlock));
|
||||
while (queue->is_full)
|
||||
{
|
||||
/* queue is full */
|
||||
@@ -131,14 +134,14 @@ rt_err_t rt_data_queue_push(struct rt_data_queue *queue,
|
||||
}
|
||||
|
||||
/* enable interrupt */
|
||||
rt_hw_interrupt_enable(level);
|
||||
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
|
||||
|
||||
/* do schedule */
|
||||
rt_schedule();
|
||||
|
||||
/* thread is waked up */
|
||||
result = thread->error;
|
||||
level = rt_hw_interrupt_disable();
|
||||
level = rt_spin_lock_irqsave(&(queue->spinlock));
|
||||
if (result != RT_EOK) goto __exit;
|
||||
}
|
||||
|
||||
@@ -165,7 +168,7 @@ rt_err_t rt_data_queue_push(struct rt_data_queue *queue,
|
||||
|
||||
/* resume it */
|
||||
rt_thread_resume(thread);
|
||||
rt_hw_interrupt_enable(level);
|
||||
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
|
||||
|
||||
/* perform a schedule */
|
||||
rt_schedule();
|
||||
@@ -174,7 +177,7 @@ rt_err_t rt_data_queue_push(struct rt_data_queue *queue,
|
||||
}
|
||||
|
||||
__exit:
|
||||
rt_hw_interrupt_enable(level);
|
||||
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
|
||||
if ((result == RT_EOK) && queue->evt_notify != RT_NULL)
|
||||
{
|
||||
queue->evt_notify(queue, RT_DATAQUEUE_EVENT_PUSH);
|
||||
@@ -222,7 +225,7 @@ rt_err_t rt_data_queue_pop(struct rt_data_queue *queue,
|
||||
result = RT_EOK;
|
||||
thread = rt_thread_self();
|
||||
|
||||
level = rt_hw_interrupt_disable();
|
||||
level = rt_spin_lock_irqsave(&(queue->spinlock));
|
||||
while (queue->is_empty)
|
||||
{
|
||||
/* queue is empty */
|
||||
@@ -249,14 +252,14 @@ rt_err_t rt_data_queue_pop(struct rt_data_queue *queue,
|
||||
}
|
||||
|
||||
/* enable interrupt */
|
||||
rt_hw_interrupt_enable(level);
|
||||
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
|
||||
|
||||
/* do schedule */
|
||||
rt_schedule();
|
||||
|
||||
/* thread is waked up */
|
||||
result = thread->error;
|
||||
level = rt_hw_interrupt_disable();
|
||||
level = rt_spin_lock_irqsave(&(queue->spinlock));
|
||||
if (result != RT_EOK)
|
||||
goto __exit;
|
||||
}
|
||||
@@ -286,14 +289,14 @@ rt_err_t rt_data_queue_pop(struct rt_data_queue *queue,
|
||||
|
||||
/* resume it */
|
||||
rt_thread_resume(thread);
|
||||
rt_hw_interrupt_enable(level);
|
||||
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
|
||||
|
||||
/* perform a schedule */
|
||||
rt_schedule();
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_hw_interrupt_enable(level);
|
||||
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
|
||||
}
|
||||
|
||||
if (queue->evt_notify != RT_NULL)
|
||||
@@ -303,7 +306,7 @@ rt_err_t rt_data_queue_pop(struct rt_data_queue *queue,
|
||||
}
|
||||
|
||||
__exit:
|
||||
rt_hw_interrupt_enable(level);
|
||||
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
|
||||
if ((result == RT_EOK) && (queue->evt_notify != RT_NULL))
|
||||
{
|
||||
queue->evt_notify(queue, RT_DATAQUEUE_EVENT_POP);
|
||||
@@ -339,12 +342,12 @@ rt_err_t rt_data_queue_peek(struct rt_data_queue *queue,
|
||||
return -RT_EEMPTY;
|
||||
}
|
||||
|
||||
level = rt_hw_interrupt_disable();
|
||||
level = rt_spin_lock_irqsave(&(queue->spinlock));
|
||||
|
||||
*data_ptr = queue->queue[queue->get_index].data_ptr;
|
||||
*size = queue->queue[queue->get_index].data_size;
|
||||
|
||||
rt_hw_interrupt_enable(level);
|
||||
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
@@ -366,14 +369,14 @@ void rt_data_queue_reset(struct rt_data_queue *queue)
|
||||
RT_ASSERT(queue != RT_NULL);
|
||||
RT_ASSERT(queue->magic == DATAQUEUE_MAGIC);
|
||||
|
||||
level = rt_hw_interrupt_disable();
|
||||
level = rt_spin_lock_irqsave(&(queue->spinlock));
|
||||
|
||||
queue->get_index = 0;
|
||||
queue->put_index = 0;
|
||||
queue->is_empty = 1;
|
||||
queue->is_full = 0;
|
||||
|
||||
rt_hw_interrupt_enable(level);
|
||||
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
|
||||
|
||||
rt_enter_critical();
|
||||
/* wakeup all suspend threads */
|
||||
@@ -382,7 +385,7 @@ void rt_data_queue_reset(struct rt_data_queue *queue)
|
||||
while (!rt_list_isempty(&(queue->suspended_pop_list)))
|
||||
{
|
||||
/* disable interrupt */
|
||||
level = rt_hw_interrupt_disable();
|
||||
level = rt_spin_lock_irqsave(&(queue->spinlock));
|
||||
|
||||
/* get next suspend thread */
|
||||
thread = rt_list_entry(queue->suspended_pop_list.next,
|
||||
@@ -399,14 +402,14 @@ void rt_data_queue_reset(struct rt_data_queue *queue)
|
||||
rt_thread_resume(thread);
|
||||
|
||||
/* enable interrupt */
|
||||
rt_hw_interrupt_enable(level);
|
||||
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
|
||||
}
|
||||
|
||||
/* resume on push list */
|
||||
while (!rt_list_isempty(&(queue->suspended_push_list)))
|
||||
{
|
||||
/* disable interrupt */
|
||||
level = rt_hw_interrupt_disable();
|
||||
level = rt_spin_lock_irqsave(&(queue->spinlock));
|
||||
|
||||
/* get next suspend thread */
|
||||
thread = rt_list_entry(queue->suspended_push_list.next,
|
||||
@@ -423,7 +426,7 @@ void rt_data_queue_reset(struct rt_data_queue *queue)
|
||||
rt_thread_resume(thread);
|
||||
|
||||
/* enable interrupt */
|
||||
rt_hw_interrupt_enable(level);
|
||||
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
|
||||
}
|
||||
rt_exit_critical();
|
||||
|
||||
@@ -448,9 +451,9 @@ rt_err_t rt_data_queue_deinit(struct rt_data_queue *queue)
|
||||
/* wakeup all suspend threads */
|
||||
rt_data_queue_reset(queue);
|
||||
|
||||
level = rt_hw_interrupt_disable();
|
||||
level = rt_spin_lock_irqsave(&(queue->spinlock));
|
||||
queue->magic = 0;
|
||||
rt_hw_interrupt_enable(level);
|
||||
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
|
||||
|
||||
rt_free(queue->queue);
|
||||
|
||||
@@ -478,7 +481,7 @@ rt_uint16_t rt_data_queue_len(struct rt_data_queue *queue)
|
||||
return 0;
|
||||
}
|
||||
|
||||
level = rt_hw_interrupt_disable();
|
||||
level = rt_spin_lock_irqsave(&(queue->spinlock));
|
||||
|
||||
if (queue->put_index > queue->get_index)
|
||||
{
|
||||
@@ -489,7 +492,7 @@ rt_uint16_t rt_data_queue_len(struct rt_data_queue *queue)
|
||||
len = queue->size + queue->put_index - queue->get_index;
|
||||
}
|
||||
|
||||
rt_hw_interrupt_enable(level);
|
||||
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2018-08-25 armink the first version
|
||||
* 2023-09-15 xqyjlj perf rt_hw_interrupt_disable/enable
|
||||
*/
|
||||
|
||||
#include <rthw.h>
|
||||
@@ -44,6 +45,7 @@ void rt_rbb_init(rt_rbb_t rbb, rt_uint8_t *buf, rt_size_t buf_size, rt_rbb_blk_t
|
||||
rt_slist_init(&block_set[i].list);
|
||||
rt_slist_insert(&rbb->free_list, &block_set[i].list);
|
||||
}
|
||||
rt_spin_lock_init(&(rbb->spinlock));
|
||||
}
|
||||
RTM_EXPORT(rt_rbb_init);
|
||||
|
||||
@@ -173,7 +175,7 @@ rt_rbb_blk_t rt_rbb_blk_alloc(rt_rbb_t rbb, rt_size_t blk_size)
|
||||
RT_ASSERT(rbb);
|
||||
RT_ASSERT(blk_size < (1L << 24));
|
||||
|
||||
level = rt_hw_interrupt_disable();
|
||||
level = rt_spin_lock_irqsave(&(rbb->spinlock));
|
||||
|
||||
new_rbb = find_empty_blk_in_set(rbb);
|
||||
|
||||
@@ -255,7 +257,7 @@ rt_rbb_blk_t rt_rbb_blk_alloc(rt_rbb_t rbb, rt_size_t blk_size)
|
||||
new_rbb = RT_NULL;
|
||||
}
|
||||
|
||||
rt_hw_interrupt_enable(level);
|
||||
rt_spin_unlock_irqrestore(&(rbb->spinlock), level);
|
||||
|
||||
return new_rbb;
|
||||
}
|
||||
@@ -294,7 +296,7 @@ rt_rbb_blk_t rt_rbb_blk_get(rt_rbb_t rbb)
|
||||
if (rt_slist_isempty(&rbb->blk_list))
|
||||
return 0;
|
||||
|
||||
level = rt_hw_interrupt_disable();
|
||||
level = rt_spin_lock_irqsave(&(rbb->spinlock));
|
||||
|
||||
for (node = rt_slist_first(&rbb->blk_list); node; node = rt_slist_next(node))
|
||||
{
|
||||
@@ -310,7 +312,7 @@ rt_rbb_blk_t rt_rbb_blk_get(rt_rbb_t rbb)
|
||||
|
||||
__exit:
|
||||
|
||||
rt_hw_interrupt_enable(level);
|
||||
rt_spin_unlock_irqrestore(&(rbb->spinlock), level);
|
||||
|
||||
return block;
|
||||
}
|
||||
@@ -360,12 +362,12 @@ void rt_rbb_blk_free(rt_rbb_t rbb, rt_rbb_blk_t block)
|
||||
RT_ASSERT(block);
|
||||
RT_ASSERT(block->status != RT_RBB_BLK_UNUSED);
|
||||
|
||||
level = rt_hw_interrupt_disable();
|
||||
level = rt_spin_lock_irqsave(&(rbb->spinlock));
|
||||
/* remove it on rbb block list */
|
||||
list_remove(rbb, &block->list);
|
||||
block->status = RT_RBB_BLK_UNUSED;
|
||||
rt_slist_insert(&rbb->free_list, &block->list);
|
||||
rt_hw_interrupt_enable(level);
|
||||
rt_spin_unlock_irqrestore(&(rbb->spinlock), level);
|
||||
}
|
||||
RTM_EXPORT(rt_rbb_blk_free);
|
||||
|
||||
@@ -405,7 +407,7 @@ rt_size_t rt_rbb_blk_queue_get(rt_rbb_t rbb, rt_size_t queue_data_len, rt_rbb_bl
|
||||
if (rt_slist_isempty(&rbb->blk_list))
|
||||
return 0;
|
||||
|
||||
level = rt_hw_interrupt_disable();
|
||||
level = rt_spin_lock_irqsave(&(rbb->spinlock));
|
||||
|
||||
node = rt_slist_first(&rbb->blk_list);
|
||||
if (node != RT_NULL)
|
||||
@@ -454,7 +456,7 @@ rt_size_t rt_rbb_blk_queue_get(rt_rbb_t rbb, rt_size_t queue_data_len, rt_rbb_bl
|
||||
blk_queue->blk_num++;
|
||||
}
|
||||
|
||||
rt_hw_interrupt_enable(level);
|
||||
rt_spin_unlock_irqrestore(&(rbb->spinlock), level);
|
||||
|
||||
return data_total_size;
|
||||
}
|
||||
@@ -541,7 +543,7 @@ rt_size_t rt_rbb_next_blk_queue_len(rt_rbb_t rbb)
|
||||
if (rt_slist_isempty(&rbb->blk_list))
|
||||
return 0;
|
||||
|
||||
level = rt_hw_interrupt_disable();
|
||||
level = rt_spin_lock_irqsave(&(rbb->spinlock));
|
||||
|
||||
for (node = rt_slist_first(&rbb->blk_list); node; node = rt_slist_next(node))
|
||||
{
|
||||
@@ -573,7 +575,7 @@ rt_size_t rt_rbb_next_blk_queue_len(rt_rbb_t rbb)
|
||||
data_len += last_block->size;
|
||||
}
|
||||
|
||||
rt_hw_interrupt_enable(level);
|
||||
rt_spin_unlock_irqrestore(&(rbb->spinlock), level);
|
||||
|
||||
return data_len;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
* 2018/06/26 Bernard Fix the wait queue issue when wakeup a soon
|
||||
* to blocked thread.
|
||||
* 2022-01-24 THEWON let rt_wqueue_wait return thread->error when using signal
|
||||
* 2023-09-15 xqyjlj perf rt_hw_interrupt_disable/enable
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
@@ -25,9 +26,10 @@ void rt_wqueue_add(rt_wqueue_t *queue, struct rt_wqueue_node *node)
|
||||
{
|
||||
rt_base_t level;
|
||||
|
||||
level = rt_hw_interrupt_disable();
|
||||
level = rt_spin_lock_irqsave(&(queue->spinlock));
|
||||
node->wqueue = queue;
|
||||
rt_list_insert_before(&(queue->waiting_list), &(node->list));
|
||||
rt_hw_interrupt_enable(level);
|
||||
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -39,9 +41,11 @@ void rt_wqueue_remove(struct rt_wqueue_node *node)
|
||||
{
|
||||
rt_base_t level;
|
||||
|
||||
level = rt_hw_interrupt_disable();
|
||||
RT_ASSERT(node->wqueue != RT_NULL);
|
||||
|
||||
level = rt_spin_lock_irqsave(&(node->wqueue->spinlock));
|
||||
rt_list_remove(&(node->list));
|
||||
rt_hw_interrupt_enable(level);
|
||||
rt_spin_unlock_irqrestore(&(node->wqueue->spinlock), level);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -79,7 +83,7 @@ void rt_wqueue_wakeup(rt_wqueue_t *queue, void *key)
|
||||
|
||||
queue_list = &(queue->waiting_list);
|
||||
|
||||
level = rt_hw_interrupt_disable();
|
||||
level = rt_spin_lock_irqsave(&(queue->spinlock));
|
||||
/* set wakeup flag in the queue */
|
||||
queue->flag = RT_WQ_FLAG_WAKEUP;
|
||||
|
||||
@@ -93,13 +97,12 @@ void rt_wqueue_wakeup(rt_wqueue_t *queue, void *key)
|
||||
rt_thread_resume(entry->polling_thread);
|
||||
need_schedule = 1;
|
||||
|
||||
rt_wqueue_remove(entry);
|
||||
rt_list_remove(&(entry->list));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
rt_hw_interrupt_enable(level);
|
||||
|
||||
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
|
||||
if (need_schedule)
|
||||
rt_schedule();
|
||||
}
|
||||
@@ -136,9 +139,10 @@ static int _rt_wqueue_wait(rt_wqueue_t *queue, int condition, int msec, int susp
|
||||
__wait.polling_thread = rt_thread_self();
|
||||
__wait.key = 0;
|
||||
__wait.wakeup = __wqueue_default_wake;
|
||||
__wait.wqueue = queue;
|
||||
rt_list_init(&__wait.list);
|
||||
|
||||
level = rt_hw_interrupt_disable();
|
||||
level = rt_spin_lock_irqsave(&(queue->spinlock));
|
||||
|
||||
/* reset thread error */
|
||||
tid->error = RT_EOK;
|
||||
@@ -152,11 +156,12 @@ static int _rt_wqueue_wait(rt_wqueue_t *queue, int condition, int msec, int susp
|
||||
ret = rt_thread_suspend_with_flag(tid, suspend_flag);
|
||||
if (ret != RT_EOK)
|
||||
{
|
||||
rt_hw_interrupt_enable(level);
|
||||
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
|
||||
/* suspend failed */
|
||||
return -RT_EINTR;
|
||||
}
|
||||
rt_wqueue_add(queue, &__wait);
|
||||
|
||||
rt_list_insert_before(&(queue->waiting_list), &(__wait.list));
|
||||
|
||||
/* start timer */
|
||||
if (tick != RT_WAITING_FOREVER)
|
||||
@@ -167,15 +172,15 @@ static int _rt_wqueue_wait(rt_wqueue_t *queue, int condition, int msec, int susp
|
||||
|
||||
rt_timer_start(tmr);
|
||||
}
|
||||
rt_hw_interrupt_enable(level);
|
||||
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
|
||||
|
||||
rt_schedule();
|
||||
|
||||
level = rt_hw_interrupt_disable();
|
||||
level = rt_spin_lock_irqsave(&(queue->spinlock));
|
||||
|
||||
__exit_wakeup:
|
||||
queue->flag = RT_WQ_FLAG_CLEAN;
|
||||
rt_hw_interrupt_enable(level);
|
||||
rt_spin_unlock_irqrestore(&(queue->spinlock), level);
|
||||
|
||||
rt_wqueue_remove(&__wait);
|
||||
|
||||
|
||||
@@ -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