Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2301_76519099
rt-thread
提交
5957e157
R
rt-thread
项目概览
2301_76519099
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
3
Star
1
Fork
1
代码
文件
提交
分支
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,发现更多精彩内容 >>
提交
5957e157
编写于
12月 31, 2020
作者:
S
shaojinchun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
cleanup操作改由当前线程退出前执行
上级
a1292576
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
50 addition
and
66 deletion
+50
-66
src/idle.c
src/idle.c
+17
-62
src/thread.c
src/thread.c
+33
-4
未找到文件。
src/idle.c
浏览文件 @
5957e157
...
...
@@ -150,82 +150,37 @@ void rt_thread_idle_excute(void)
{
/* Loop until there is no dead thread. So one call to rt_thread_idle_excute
* will do all the cleanups. */
while
(
_has_defunct_thread
())
/* disable interrupt */
RT_DEBUG_NOT_IN_INTERRUPT
;
#ifdef RT_USING_HEAP
while
(
1
)
{
rt_base_t
lock
;
rt_thread_t
thread
;
#ifdef RT_USING_MODULE
struct
rt_dlmodule
*
module
=
RT_NULL
;
#endif
RT_DEBUG_NOT_IN_INTERRUPT
;
/* disable interrupt */
lock
=
rt_hw_interrupt_disable
();
/*
re-
check whether list is empty */
if
(
_has_defunct_thread
())
/* check whether list is empty */
if
(
!
_has_defunct_thread
())
{
rt_hw_interrupt_enable
(
lock
);
break
;
}
/* get defunct thread */
thread
=
rt_list_entry
(
rt_thread_defunct
.
next
,
struct
rt_thread
,
tlist
);
#ifdef RT_USING_MODULE
module
=
(
struct
rt_dlmodule
*
)
thread
->
module_id
;
if
(
module
)
{
dlmodule_destroy
(
module
);
}
#endif
/* remove defunct thread */
rt_list_remove
(
&
(
thread
->
tlist
));
/* lock scheduler to prevent scheduling in cleanup function. */
rt_enter_critical
();
/* invoke thread cleanup */
if
(
thread
->
cleanup
!=
RT_NULL
)
thread
->
cleanup
(
thread
);
#ifdef RT_USING_SIGNALS
rt_thread_free_sig
(
thread
);
#endif
/* if it's a system object, not delete it */
if
(
rt_object_is_systemobject
((
rt_object_t
)
thread
)
==
RT_TRUE
)
{
/* detach this object */
rt_object_detach
((
rt_object_t
)
thread
);
/* unlock scheduler */
rt_exit_critical
();
/* enable interrupt */
rt_hw_interrupt_enable
(
lock
);
return
;
}
/* unlock scheduler */
rt_exit_critical
();
}
else
{
/* enable interrupt */
rt_hw_interrupt_enable
(
lock
);
/* may the defunct thread list is removed by others, just return */
return
;
}
/* enable interrupt */
rt_hw_interrupt_enable
(
lock
);
#ifdef RT_USING_HEAP
/* release thread's stack */
RT_KERNEL_FREE
(
thread
->
stack_addr
);
/* delete thread object */
rt_object_delete
((
rt_object_t
)
thread
);
#endif
rt_hw_interrupt_enable
(
lock
);
}
#endif
}
extern
void
rt_system_power_manager
(
void
);
...
...
src/thread.c
浏览文件 @
5957e157
...
...
@@ -77,6 +77,31 @@ void rt_thread_inited_sethook(void (*hook)(rt_thread_t thread))
#endif
/* must be invoke witch rt_hw_interrupt_disable */
static
void
_thread_cleanup_execute
(
rt_thread_t
thread
)
{
register
rt_base_t
level
;
#ifdef RT_USING_MODULE
struct
rt_dlmodule
*
module
=
RT_NULL
;
#endif
level
=
rt_hw_interrupt_disable
();
#ifdef RT_USING_MODULE
module
=
(
struct
rt_dlmodule
*
)
thread
->
module_id
;
if
(
module
)
{
dlmodule_destroy
(
module
);
}
#endif
/* invoke thread cleanup */
if
(
thread
->
cleanup
!=
RT_NULL
)
thread
->
cleanup
(
thread
);
#ifdef RT_USING_SIGNALS
rt_thread_free_sig
(
thread
);
#endif
rt_hw_interrupt_enable
(
level
);
}
void
rt_thread_exit
(
void
)
{
struct
rt_thread
*
thread
;
...
...
@@ -88,6 +113,8 @@ void rt_thread_exit(void)
/* disable interrupt */
level
=
rt_hw_interrupt_disable
();
_thread_cleanup_execute
(
thread
);
/* remove from schedule */
rt_schedule_remove_thread
(
thread
);
/* change stat */
...
...
@@ -96,8 +123,7 @@ void rt_thread_exit(void)
/* remove it from timer list */
rt_timer_detach
(
&
thread
->
thread_timer
);
if
((
rt_object_is_systemobject
((
rt_object_t
)
thread
)
==
RT_TRUE
)
&&
thread
->
cleanup
==
RT_NULL
)
if
(
rt_object_is_systemobject
((
rt_object_t
)
thread
)
==
RT_TRUE
)
{
rt_object_detach
((
rt_object_t
)
thread
);
}
...
...
@@ -347,14 +373,15 @@ rt_err_t rt_thread_detach(rt_thread_t thread)
rt_schedule_remove_thread
(
thread
);
}
_thread_cleanup_execute
(
thread
);
/* release thread timer */
rt_timer_detach
(
&
(
thread
->
thread_timer
));
/* change stat */
thread
->
stat
=
RT_THREAD_CLOSE
;
if
((
rt_object_is_systemobject
((
rt_object_t
)
thread
)
==
RT_TRUE
)
&&
thread
->
cleanup
==
RT_NULL
)
if
(
rt_object_is_systemobject
((
rt_object_t
)
thread
)
==
RT_TRUE
)
{
rt_object_detach
((
rt_object_t
)
thread
);
}
...
...
@@ -449,6 +476,8 @@ rt_err_t rt_thread_delete(rt_thread_t thread)
rt_schedule_remove_thread
(
thread
);
}
_thread_cleanup_execute
(
thread
);
/* release thread timer */
rt_timer_detach
(
&
(
thread
->
thread_timer
));
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录