🎈 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:
xqyjlj
2023-10-25 20:31:25 +08:00
committed by GitHub
co-authored by Shell
parent 91fc52df36
commit 3283f54c7a
80 changed files with 2478 additions and 1962 deletions
+8 -7
View File
@@ -6,6 +6,7 @@
* Change Logs:
* Date Author Notes
* 2021-08-25 RT-Thread First version
* 2023-09-15 xqyjlj perf rt_hw_interrupt_disable/enable
*/
#include <rthw.h>
#include <rtthread.h>
@@ -19,6 +20,7 @@ void resource_id_init(resource_id_t *mgr, int size, void **res)
mgr->_res = res;
mgr->noused = 0;
mgr->_free = RT_NULL;
rt_spin_lock_init(&(mgr->spinlock));
}
}
@@ -27,21 +29,21 @@ int resource_id_get(resource_id_t *mgr)
rt_base_t level;
void **cur;
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&(mgr->spinlock));
if (mgr->_free)
{
cur = mgr->_free;
mgr->_free = (void **)*mgr->_free;
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(mgr->spinlock), level);
return cur - mgr->_res;
}
else if (mgr->noused < mgr->size)
{
cur = &mgr->_res[mgr->noused++];
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(mgr->spinlock), level);
return cur - mgr->_res;
}
rt_hw_interrupt_enable(level);
return -1;
}
@@ -52,11 +54,10 @@ void resource_id_put(resource_id_t *mgr, int no)
if (no >= 0 && no < mgr->size)
{
level = rt_hw_interrupt_disable();
level = rt_spin_lock_irqsave(&(mgr->spinlock));
cur = &mgr->_res[no];
*cur = (void *)mgr->_free;
mgr->_free = cur;
rt_hw_interrupt_enable(level);
rt_spin_unlock_irqrestore(&(mgr->spinlock), level);
}
}
+3 -1
View File
@@ -6,6 +6,7 @@
* Change Logs:
* Date Author Notes
* 2021-08-25 RT-Thread First version
* 2023-09-15 xqyjlj perf rt_hw_interrupt_disable/enable
*/
#ifndef RESOURCE_ID_H__
@@ -14,7 +15,7 @@
#include <rthw.h>
#include <rtthread.h>
#define RESOURCE_ID_INIT(size, pool) {size, pool, 0, RT_NULL}
#define RESOURCE_ID_INIT(size, pool) {size, pool, 0, RT_NULL, RT_SPINLOCK_INIT}
typedef struct
{
@@ -22,6 +23,7 @@ typedef struct
void **_res;
int noused;
void **_free;
struct rt_spinlock spinlock;
} resource_id_t;
void resource_id_init(resource_id_t *mgr, int size, void **res);