Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
混口饭吃,
rt-thread
提交
c003bdf4
R
rt-thread
项目概览
混口饭吃,
/
rt-thread
与 Fork 源项目一致
Fork自
Mr_Pangza / 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,发现更多精彩内容 >>
提交
c003bdf4
编写于
2月 07, 2019
作者:
B
Bernard Xiong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[pthreads] Add _pthread_destroy to release pthread resource.
上级
25988d30
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
60 addition
and
33 deletion
+60
-33
components/libc/pthreads/pthread.c
components/libc/pthreads/pthread.c
+60
-33
未找到文件。
components/libc/pthreads/pthread.c
浏览文件 @
c003bdf4
...
...
@@ -7,6 +7,7 @@
* Date Author Notes
* 2018-01-26 Bernard Fix pthread_detach issue for a none-joinable
* thread.
* 2019-02-07 Bernard Add _pthread_destroy to release pthread resource.
*/
#include <pthread.h>
...
...
@@ -26,6 +27,32 @@ int pthread_system_init(void)
}
INIT_COMPONENT_EXPORT
(
pthread_system_init
);
static
void
_pthread_destroy
(
_pthread_data_t
*
ptd
)
{
/* delete joinable semaphore */
if
(
ptd
->
joinable_sem
!=
RT_NULL
)
rt_sem_delete
(
ptd
->
joinable_sem
);
/* release thread resource */
if
(
ptd
->
attr
.
stack_base
==
RT_NULL
)
{
/* release thread allocated stack */
rt_free
(
ptd
->
tid
->
stack_addr
);
}
/* clean stack addr pointer */
ptd
->
tid
->
stack_addr
=
RT_NULL
;
/*
* if this thread create the local thread data,
* delete it
*/
if
(
ptd
->
tls
!=
RT_NULL
)
rt_free
(
ptd
->
tls
);
rt_free
(
ptd
->
tid
);
rt_free
(
ptd
);
return
;
}
static
void
_pthread_cleanup
(
rt_thread_t
tid
)
{
_pthread_data_t
*
ptd
;
...
...
@@ -40,14 +67,14 @@ static void _pthread_cleanup(rt_thread_t tid)
else
{
/* release pthread resource */
pthread_detach
(
ti
d
);
_pthread_destroy
(
pt
d
);
}
}
static
void
pthread_entry_stub
(
void
*
parameter
)
{
_pthread_data_t
*
ptd
;
void
*
value
;
_pthread_data_t
*
ptd
;
ptd
=
(
_pthread_data_t
*
)
parameter
;
...
...
@@ -181,60 +208,60 @@ RTM_EXPORT(pthread_create);
int
pthread_detach
(
pthread_t
thread
)
{
_pthread_data_t
*
ptd
;
ptd
=
_pthread_get_data
(
thread
);
int
ret
=
0
;
_pthread_data_t
*
ptd
=
_pthread_get_data
(
thread
);
rt_enter_critical
();
if
(
ptd
->
attr
.
detachstate
==
PTHREAD_CREATE_DETACHED
)
{
/* The implementation has detected that the value specified by thread does not refer
* to a joinable thread.
*/
return
EINVAL
;
ret
=
EINVAL
;
goto
__exit
;
}
if
((
thread
->
stat
&
RT_THREAD_STAT_MASK
)
==
RT_THREAD_CLOSE
)
{
/* delete joinable semaphore */
if
(
ptd
->
joinable_sem
!=
RT_NULL
)
rt_sem_delete
(
ptd
->
joinable_sem
);
/* detach thread object */
rt_thread_detach
(
ptd
->
tid
);
/* this defunct pthread is not handled by idle */
if
(
rt_sem_trytake
(
ptd
->
joinable_sem
)
!=
RT_EOK
)
{
rt_sem_release
(
ptd
->
joinable_sem
);
/* release thread resource */
if
(
ptd
->
attr
.
stack_base
==
RT_NULL
)
/* change to detach state */
ptd
->
attr
.
detachstate
=
PTHREAD_CREATE_DETACHED
;
/* detach joinable semaphore */
if
(
ptd
->
joinable_sem
)
{
/* release thread allocated stack */
rt_free
(
ptd
->
tid
->
stack_addr
);
rt_sem_delete
(
ptd
->
joinable_sem
);
ptd
->
joinable_sem
=
RT_NULL
;
}
}
else
{
/*
clean stack addr pointer
*/
ptd
->
tid
->
stack_addr
=
RT_NULL
;
/*
destroy this pthread
*/
_pthread_destroy
(
ptd
)
;
}
/*
* if this thread create the local thread data,
* delete it
*/
if
(
ptd
->
tls
!=
RT_NULL
)
rt_free
(
ptd
->
tls
);
rt_free
(
ptd
->
tid
);
rt_free
(
ptd
);
goto
__exit
;
}
else
{
rt_enter_critical
();
/* change to detach state */
ptd
->
attr
.
detachstate
=
PTHREAD_CREATE_DETACHED
;
/* detach joinable semaphore */
if
(
ptd
->
joinable_sem
)
{
rt_sem_delete
(
ptd
->
joinable_sem
);
ptd
->
joinable_sem
=
RT_NULL
;
rt_exit_critical
();
}
}
return
0
;
__exit:
rt_exit_critical
();
return
ret
;
}
RTM_EXPORT
(
pthread_detach
);
...
...
@@ -260,8 +287,8 @@ int pthread_join(pthread_t thread, void **value_ptr)
if
(
value_ptr
!=
RT_NULL
)
*
value_ptr
=
ptd
->
return_value
;
/*
release resource
*/
pthread_detach
(
threa
d
);
/*
destroy this pthread
*/
_pthread_destroy
(
pt
d
);
}
else
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录