Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wwsmg1
rt-thread
提交
b8aaa6e7
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,发现更多精彩内容 >>
提交
b8aaa6e7
编写于
1月 16, 2013
作者:
P
prife
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
clean code in cpu_port.c, add some comments
上级
b8bd5c83
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
14 addition
and
12 deletion
+14
-12
libcpu/sim/posix/cpu_port.c
libcpu/sim/posix/cpu_port.c
+14
-12
未找到文件。
libcpu/sim/posix/cpu_port.c
浏览文件 @
b8aaa6e7
...
@@ -46,7 +46,7 @@ typedef struct _thread
...
@@ -46,7 +46,7 @@ typedef struct _thread
/* interrupt flag, if 1, disable, if 0, enable */
/* interrupt flag, if 1, disable, if 0, enable */
static
long
interrupt_disable_flag
;
static
long
interrupt_disable_flag
;
static
int
systick_signal_flag
;
//
static int systick_signal_flag;
/* flag in interrupt handling */
/* flag in interrupt handling */
rt_uint32_t
rt_interrupt_from_thread
,
rt_interrupt_to_thread
;
rt_uint32_t
rt_interrupt_from_thread
,
rt_interrupt_to_thread
;
...
@@ -154,7 +154,7 @@ static void *thread_run(void *parameter)
...
@@ -154,7 +154,7 @@ static void *thread_run(void *parameter)
thread
=
THREAD_T
(
parameter
);
thread
=
THREAD_T
(
parameter
);
int
res
;
int
res
;
/*
FIXME
set signal mask, mask the timer! */
/* set signal mask, mask the timer! */
signal_mask
();
signal_mask
();
thread
->
status
=
SUSPEND_LOCK
;
thread
->
status
=
SUSPEND_LOCK
;
...
@@ -169,7 +169,13 @@ static void *thread_run(void *parameter)
...
@@ -169,7 +169,13 @@ static void *thread_run(void *parameter)
TRACE
(
"pid <%08x> tid <%s> exit...
\n
"
,
(
unsigned
int
)(
thread
->
pthread
),
TRACE
(
"pid <%08x> tid <%s> exit...
\n
"
,
(
unsigned
int
)(
thread
->
pthread
),
tid
->
name
);
tid
->
name
);
thread
->
exit
();
thread
->
exit
();
//sem_destroy(&thread->sem); //<--------------
/*TODO:
* 最后一行的pthread_exit永远没有机会执行,这是因为在threead->exit函数中
* 会发生线程切换,并永久将此pthread线程挂起,所以更完美的解决方案是在这
* 里发送信号给主线程,主线程中再次唤醒此线程令其自动退出。
*/
//sem_destroy(&thread->sem);
pthread_exit
(
NULL
);
pthread_exit
(
NULL
);
}
}
...
@@ -309,11 +315,9 @@ void rt_hw_interrupt_enable(rt_base_t level)
...
@@ -309,11 +315,9 @@ void rt_hw_interrupt_enable(rt_base_t level)
/* 挂起当前的线程 */
/* 挂起当前的线程 */
sem_wait
(
&
thread_from
->
sem
);
sem_wait
(
&
thread_from
->
sem
);
//TRACE("rttask:%s suspend!\n", thread_from->rtthread->name);
pthread_mutex_lock
(
ptr_int_mutex
);
pthread_mutex_lock
(
ptr_int_mutex
);
thread_from
->
status
=
THREAD_RUNNING
;
thread_from
->
status
=
THREAD_RUNNING
;
pthread_mutex_unlock
(
ptr_int_mutex
);
pthread_mutex_unlock
(
ptr_int_mutex
);
//TRACE("rttask:%s resume!\n", thread_to->rtthread->name);
}
}
else
else
{
{
...
@@ -333,7 +337,7 @@ void rt_hw_interrupt_enable(rt_base_t level)
...
@@ -333,7 +337,7 @@ void rt_hw_interrupt_enable(rt_base_t level)
/* 挂起from线程 */
/* 挂起from线程 */
pthread_kill
(
thread_from
->
pthread
,
MSG_SUSPEND
);
pthread_kill
(
thread_from
->
pthread
,
MSG_SUSPEND
);
/*
TODO 这里需要确保线程被挂起了, 否则304
行就很可能就会报错退出
/*
注意:这里需要确保线程被挂起了, 否则312
行就很可能就会报错退出
* 因为这里挂起线程是通过信号实现的,所以一定要确保线程挂起才行 */
* 因为这里挂起线程是通过信号实现的,所以一定要确保线程挂起才行 */
while
(
thread_from
->
status
!=
SUSPEND_SIGWAIT
)
while
(
thread_from
->
status
!=
SUSPEND_SIGWAIT
)
{
{
...
@@ -376,7 +380,7 @@ void rt_hw_context_switch(rt_uint32_t from,
...
@@ -376,7 +380,7 @@ void rt_hw_context_switch(rt_uint32_t from,
RT_ASSERT
(
from
!=
to
);
RT_ASSERT
(
from
!=
to
);
#if 0
#if 0
//TODO: 还需要考虑嵌套切换的情况
//TODO:
可能
还需要考虑嵌套切换的情况
if (rt_thread_switch_interrupt_flag != 1)
if (rt_thread_switch_interrupt_flag != 1)
{
{
rt_thread_switch_interrupt_flag = 1;
rt_thread_switch_interrupt_flag = 1;
...
@@ -449,14 +453,12 @@ static int mainthread_scheduler(void)
...
@@ -449,14 +453,12 @@ static int mainthread_scheduler(void)
/* create a mutex and condition val, used to indicate interrupts occrue */
/* create a mutex and condition val, used to indicate interrupts occrue */
ptr_int_mutex
=
&
mutex
;
ptr_int_mutex
=
&
mutex
;
pthread_mutexattr_init
(
&
mutexattr
);
pthread_mutexattr_init
(
&
mutexattr
);
pthread_mutexattr_settype
(
&
mutexattr
,
PTHREAD_MUTEX_RECURSIVE
);
pthread_mutexattr_settype
(
&
mutexattr
,
PTHREAD_MUTEX_RECURSIVE
_NP
);
pthread_mutex_init
(
ptr_int_mutex
,
&
mutexattr
);
pthread_mutex_init
(
ptr_int_mutex
,
&
mutexattr
);
/* start timer */
/* start timer */
start_sys_timer
();
start_sys_timer
();
/* FIXME: note that, cond var could not released earlier than pthread_con_wait */
/* trigger_interrupt(CPU_INTERRUPT_YIELD); */
thread_to
=
(
thread_t
*
)
rt_interrupt_to_thread
;
thread_to
=
(
thread_t
*
)
rt_interrupt_to_thread
;
thread_resume
(
thread_to
);
thread_resume
(
thread_to
);
for
(;;)
for
(;;)
...
@@ -473,11 +475,11 @@ static int mainthread_scheduler(void)
...
@@ -473,11 +475,11 @@ static int mainthread_scheduler(void)
/* signal mask sigalrm 屏蔽SIGALRM信号 */
/* signal mask sigalrm 屏蔽SIGALRM信号 */
pthread_sigmask
(
SIG_BLOCK
,
&
sigmask
,
&
oldmask
);
pthread_sigmask
(
SIG_BLOCK
,
&
sigmask
,
&
oldmask
);
//
if (systick_signal_flag != 0)
//
if (systick_signal_flag != 0)
if
(
pthread_mutex_trylock
(
ptr_int_mutex
)
==
0
)
if
(
pthread_mutex_trylock
(
ptr_int_mutex
)
==
0
)
{
{
tick_interrupt_isr
();
tick_interrupt_isr
();
systick_signal_flag
=
0
;
//
systick_signal_flag = 0;
pthread_mutex_unlock
(
ptr_int_mutex
);
pthread_mutex_unlock
(
ptr_int_mutex
);
}
}
else
else
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录