Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wwsmg1
rt-thread
提交
5cd65092
R
rt-thread
项目概览
wwsmg1
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
5cd65092
编写于
9月 28, 2019
作者:
B
Bernard Xiong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Kernel] cleanup code of spinlock in SMP Kernel
上级
cb07e5fb
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
42 addition
and
47 deletion
+42
-47
include/rthw.h
include/rthw.h
+2
-10
include/rtthread.h
include/rtthread.h
+21
-0
src/SConscript
src/SConscript
+3
-0
src/cpu.c
src/cpu.c
+16
-37
未找到文件。
include/rthw.h
浏览文件 @
5cd65092
...
...
@@ -143,10 +143,10 @@ typedef union {
}
tickets
;
}
rt_hw_spinlock_t
;
typedef
struct
struct
rt_spinlock
{
rt_hw_spinlock_t
lock
;
}
rt_spinlock_t
;
};
void
rt_hw_spin_lock_init
(
rt_hw_spinlock_t
*
lock
);
void
rt_hw_spin_lock
(
rt_hw_spinlock_t
*
lock
);
...
...
@@ -187,16 +187,8 @@ void rt_hw_secondary_cpu_idle_exec(void);
#define rt_hw_spin_lock(lock) *(lock) = rt_hw_interrupt_disable()
#define rt_hw_spin_unlock(lock) rt_hw_interrupt_enable(*(lock))
typedef
int
rt_spinlock_t
;
#endif
void
rt_spin_lock_init
(
rt_spinlock_t
*
lock
);
void
rt_spin_lock
(
rt_spinlock_t
*
lock
);
void
rt_spin_unlock
(
rt_spinlock_t
*
lock
);
rt_base_t
rt_spin_lock_irqsave
(
rt_spinlock_t
*
lock
);
void
rt_spin_unlock_irqrestore
(
rt_spinlock_t
*
lock
,
rt_base_t
level
);
#ifdef __cplusplus
}
#endif
...
...
include/rtthread.h
浏览文件 @
5cd65092
...
...
@@ -391,6 +391,27 @@ rt_err_t rt_mq_recv(rt_mq_t mq,
rt_err_t
rt_mq_control
(
rt_mq_t
mq
,
int
cmd
,
void
*
arg
);
#endif
/*
* spinlock
*/
#ifdef RT_USING_SMP
struct
rt_spinlock
;
void
rt_spin_lock_init
(
struct
rt_spinlock
*
lock
);
void
rt_spin_lock
(
struct
rt_spinlock
*
lock
);
void
rt_spin_unlock
(
struct
rt_spinlock
*
lock
);
rt_base_t
rt_spin_lock_irqsave
(
struct
rt_spinlock
*
lock
);
void
rt_spin_unlock_irqrestore
(
struct
rt_spinlock
*
lock
,
rt_base_t
level
);
#else
#define rt_spin_lock_init(lock)
/* nothing */
#define rt_spin_lock(lock) rt_enter_critical()
#define rt_spin_unlock(lock) rt_exit_critical()
#define rt_spin_lock_irqsave(lock) rt_hw_interrupt_disable()
#define rt_spin_unlock_irqrestore(lock, level) rt_hw_interrupt_enable(level)
#endif
/**@}*/
#ifdef RT_USING_DEVICE
...
...
src/SConscript
浏览文件 @
5cd65092
...
...
@@ -26,6 +26,9 @@ if GetDepend('RT_USING_MEMHEAP') == False:
if
GetDepend
(
'RT_USING_DEVICE'
)
==
False
:
SrcRemove
(
src
,
[
'device.c'
])
if
GetDepend
(
'RT_USING_SMP'
)
==
False
:
SrcRemove
(
src
,
[
'cpu.c'
])
group
=
DefineGroup
(
'Kernel'
,
src
,
depend
=
[
''
],
CPPPATH
=
CPPPATH
)
Return
(
'group'
)
src/cpu.c
浏览文件 @
5cd65092
...
...
@@ -12,9 +12,12 @@
#include <rthw.h>
#ifdef RT_USING_SMP
/***********************************
static
struct
rt_cpu
rt_cpus
[
RT_CPUS_NR
];
rt_hw_spinlock_t
_cpus_lock
;
/*
* disable scheduler
*
**********************************
/
*/
static
void
rt_preempt_disable
(
void
)
{
register
rt_base_t
level
;
...
...
@@ -23,7 +26,7 @@ static void rt_preempt_disable(void)
/* disable interrupt */
level
=
rt_hw_local_irq_disable
();
current_thread
=
rt_
cpu_self
()
->
current_thread
;
current_thread
=
rt_
thread_self
()
;
if
(
!
current_thread
)
{
rt_hw_local_irq_enable
(
level
);
...
...
@@ -37,9 +40,9 @@ static void rt_preempt_disable(void)
rt_hw_local_irq_enable
(
level
);
}
/*
**********************************
*
restor
e scheduler
*
**********************************
/
/*
*
enabl
e scheduler
*/
static
void
rt_preempt_enable
(
void
)
{
register
rt_base_t
level
;
...
...
@@ -48,7 +51,7 @@ static void rt_preempt_enable(void)
/* disable interrupt */
level
=
rt_hw_local_irq_disable
();
current_thread
=
rt_
cpu_self
()
->
current_thread
;
current_thread
=
rt_
thread_self
()
;
if
(
!
current_thread
)
{
rt_hw_local_irq_enable
(
level
);
...
...
@@ -62,73 +65,49 @@ static void rt_preempt_enable(void)
/* enable interrupt */
rt_hw_local_irq_enable
(
level
);
}
#endif
void
rt_spin_lock_init
(
rt_spinlock_t
*
lock
)
void
rt_spin_lock_init
(
struct
rt_spinlock
*
lock
)
{
#ifdef RT_USING_SMP
rt_hw_spin_lock_init
(
&
lock
->
lock
);
#endif
}
RTM_EXPORT
(
rt_spin_lock_init
)
void
rt_spin_lock
(
rt_spinlock_t
*
lock
)
void
rt_spin_lock
(
struct
rt_spinlock
*
lock
)
{
#ifdef RT_USING_SMP
rt_preempt_disable
();
rt_hw_spin_lock
(
&
lock
->
lock
);
#else
rt_enter_critical
();
#endif
}
RTM_EXPORT
(
rt_spin_lock
)
void
rt_spin_unlock
(
rt_spinlock_t
*
lock
)
void
rt_spin_unlock
(
struct
rt_spinlock
*
lock
)
{
#ifdef RT_USING_SMP
rt_hw_spin_unlock
(
&
lock
->
lock
);
rt_preempt_enable
();
#else
rt_exit_critical
();
#endif
}
RTM_EXPORT
(
rt_spin_unlock
)
rt_base_t
rt_spin_lock_irqsave
(
rt_spinlock_t
*
lock
)
rt_base_t
rt_spin_lock_irqsave
(
struct
rt_spinlock
*
lock
)
{
unsigned
long
level
;
#ifdef RT_USING_SMP
rt_preempt_disable
();
level
=
rt_hw_local_irq_disable
();
rt_hw_spin_lock
(
&
lock
->
lock
);
return
level
;
#else
return
rt_hw_interrupt_disable
();
#endif
}
RTM_EXPORT
(
rt_spin_lock_irqsave
)
void
rt_spin_unlock_irqrestore
(
rt_spinlock_t
*
lock
,
rt_base_t
level
)
void
rt_spin_unlock_irqrestore
(
struct
rt_spinlock
*
lock
,
rt_base_t
level
)
{
#ifdef RT_USING_SMP
rt_hw_spin_unlock
(
&
lock
->
lock
);
rt_hw_local_irq_enable
(
level
);
rt_preempt_enable
();
#else
rt_hw_interrupt_enable
(
level
);
#endif
}
RTM_EXPORT
(
rt_spin_unlock_irqrestore
)
#ifdef RT_USING_SMP
static
struct
rt_cpu
rt_cpus
[
RT_CPUS_NR
];
rt_hw_spinlock_t
_cpus_lock
;
/**
* This fucntion will return current cpu.
*/
...
...
@@ -155,7 +134,7 @@ rt_base_t rt_cpus_lock(void)
pcpu
=
rt_cpu_self
();
if
(
pcpu
->
current_thread
!=
RT_NULL
)
{
register
rt_u
int16
_t
lock_nest
=
pcpu
->
current_thread
->
cpus_lock_nest
;
register
rt_u
base
_t
lock_nest
=
pcpu
->
current_thread
->
cpus_lock_nest
;
pcpu
->
current_thread
->
cpus_lock_nest
++
;
if
(
lock_nest
==
0
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录