Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
rt-thread
提交
2b98ac21
R
rt-thread
项目概览
BaiXuePrincess
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
1
Star
0
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,发现更多精彩内容 >>
提交
2b98ac21
编写于
2月 24, 2021
作者:
mysterywolf
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[kernel] rearrange rt_thread_control() - schedule the thread when close it
上级
c21f018b
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
77 addition
and
74 deletion
+77
-74
components/libc/compilers/common/stdlib.c
components/libc/compilers/common/stdlib.c
+1
-9
src/thread.c
src/thread.c
+76
-65
未找到文件。
components/libc/compilers/common/stdlib.c
浏览文件 @
2b98ac21
...
...
@@ -14,18 +14,10 @@ void __rt_libc_exit(int status)
{
rt_thread_t
self
=
rt_thread_self
();
#ifdef RT_USING_MODULE
if
(
dlmodule_self
())
{
dlmodule_exit
(
status
);
}
#endif
if
(
self
!=
RT_NULL
)
{
rt_kprintf
(
"thread:%s exit:%d!
\n
"
,
self
->
name
,
status
);
rt_thread_suspend
(
self
);
rt_schedule
();
rt_thread_control
(
self
,
RT_THREAD_CTRL_CLOSE
,
RT_NULL
);
}
}
...
...
src/thread.c
浏览文件 @
2b98ac21
...
...
@@ -26,6 +26,7 @@
* bug when thread has not startup.
* 2018-11-22 Jesven yield is same to rt_schedule
* add support for tasks bound to cpu
* 2021-02-24 Meco Man rearrange rt_thread_control() - schedule the thread when close it
*/
#include <rthw.h>
...
...
@@ -670,83 +671,93 @@ rt_err_t rt_thread_control(rt_thread_t thread, int cmd, void *arg)
switch
(
cmd
)
{
case
RT_THREAD_CTRL_CHANGE_PRIORITY
:
/* disable interrupt */
temp
=
rt_hw_interrupt_disable
();
/* for ready thread, change queue */
if
((
thread
->
stat
&
RT_THREAD_STAT_MASK
)
==
RT_THREAD_READY
)
case
RT_THREAD_CTRL_CHANGE_PRIORITY
:
{
/* remove thread from schedule queue first */
rt_schedule_remove_thread
(
thread
);
/* change thread priority */
thread
->
current_priority
=
*
(
rt_uint8_t
*
)
arg
;
/* recalculate priority attribute */
#if RT_THREAD_PRIORITY_MAX > 32
thread
->
number
=
thread
->
current_priority
>>
3
;
/* 5bit */
thread
->
number_mask
=
1
<<
thread
->
number
;
thread
->
high_mask
=
1
<<
(
thread
->
current_priority
&
0x07
);
/* 3bit */
#else
thread
->
number_mask
=
1
<<
thread
->
current_priority
;
#endif
/* insert thread to schedule queue again */
rt_schedule_insert_thread
(
thread
);
/* disable interrupt */
temp
=
rt_hw_interrupt_disable
();
/* for ready thread, change queue */
if
((
thread
->
stat
&
RT_THREAD_STAT_MASK
)
==
RT_THREAD_READY
)
{
/* remove thread from schedule queue first */
rt_schedule_remove_thread
(
thread
);
/* change thread priority */
thread
->
current_priority
=
*
(
rt_uint8_t
*
)
arg
;
/* recalculate priority attribute */
#if RT_THREAD_PRIORITY_MAX > 32
thread
->
number
=
thread
->
current_priority
>>
3
;
/* 5bit */
thread
->
number_mask
=
1
<<
thread
->
number
;
thread
->
high_mask
=
1
<<
(
thread
->
current_priority
&
0x07
);
/* 3bit */
#else
thread
->
number_mask
=
1
<<
thread
->
current_priority
;
#endif
/* insert thread to schedule queue again */
rt_schedule_insert_thread
(
thread
);
}
else
{
thread
->
current_priority
=
*
(
rt_uint8_t
*
)
arg
;
/* recalculate priority attribute */
#if RT_THREAD_PRIORITY_MAX > 32
thread
->
number
=
thread
->
current_priority
>>
3
;
/* 5bit */
thread
->
number_mask
=
1
<<
thread
->
number
;
thread
->
high_mask
=
1
<<
(
thread
->
current_priority
&
0x07
);
/* 3bit */
#else
thread
->
number_mask
=
1
<<
thread
->
current_priority
;
#endif
}
/* enable interrupt */
rt_hw_interrupt_enable
(
temp
);
break
;
}
else
{
thread
->
current_priority
=
*
(
rt_uint8_t
*
)
arg
;
/* recalculate priority attribute */
#if RT_THREAD_PRIORITY_MAX > 32
thread
->
number
=
thread
->
current_priority
>>
3
;
/* 5bit */
thread
->
number_mask
=
1
<<
thread
->
number
;
thread
->
high_mask
=
1
<<
(
thread
->
current_priority
&
0x07
);
/* 3bit */
#else
thread
->
number_mask
=
1
<<
thread
->
current_priority
;
#endif
case
RT_THREAD_CTRL_STARTUP
:
{
return
rt_thread_startup
(
thread
);
}
/* enable interrupt */
rt_hw_interrupt_enable
(
temp
);
break
;
case
RT_THREAD_CTRL_STARTUP
:
return
rt_thread_startup
(
thread
);
case
RT_THREAD_CTRL_CLOSE
:
if
(
rt_object_is_systemobject
((
rt_object_t
)
thread
)
==
RT_TRUE
)
case
RT_THREAD_CTRL_CLOSE
:
{
return
rt_thread_detach
(
thread
);
rt_err_t
rt_err
;
if
(
rt_object_is_systemobject
((
rt_object_t
)
thread
)
==
RT_TRUE
)
{
rt_err
=
rt_thread_detach
(
thread
);
}
#ifdef RT_USING_HEAP
else
{
rt_err
=
rt_thread_delete
(
thread
);
}
#endif
rt_schedule
();
return
rt_err
;
}
#ifdef RT_USING_HEAP
else
#ifdef RT_USING_SMP
case
RT_THREAD_CTRL_BIND_CPU
:
{
return
rt_thread_delete
(
thread
);
}
#endif
rt_uint8_t
cpu
;
#ifdef RT_USING_SMP
case
RT_THREAD_CTRL_BIND_CPU
:
{
rt_uint8_t
cpu
;
if
((
thread
->
stat
&
RT_THREAD_STAT_MASK
)
!=
RT_THREAD_INIT
)
{
/* we only support bind cpu before started phase. */
return
RT_ERROR
;
}
if
((
thread
->
stat
&
RT_THREAD_STAT_MASK
)
!=
RT_THREAD_INIT
)
{
/* we only support bind cpu before started phase. */
return
RT_ERROR
;
cpu
=
(
rt_uint8_t
)(
size_t
)
arg
;
thread
->
bind_cpu
=
cpu
>
RT_CPUS_NR
?
RT_CPUS_NR
:
cpu
;
break
;
}
#endif
/*RT_USING_SMP*/
cpu
=
(
rt_uint8_t
)(
size_t
)
arg
;
thread
->
bind_cpu
=
cpu
>
RT_CPUS_NR
?
RT_CPUS_NR
:
cpu
;
break
;
}
#endif
/*RT_USING_SMP*/
default:
break
;
default:
break
;
}
return
RT_EOK
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录