Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Musl
提交
7d383b13
T
Third Party Musl
项目概览
OpenHarmony
/
Third Party Musl
1 年多 前同步成功
通知
37
Star
125
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
Third Party Musl
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
7d383b13
编写于
1月 06, 2022
作者:
些猜
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
新增API pthread_gettid()
Signed-off-by:
caifuzhou
<
504631861@qq.com
>
上级
93285f22
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
77 addition
and
0 deletion
+77
-0
libc-test/src/functional/pthread_gettid.c
libc-test/src/functional/pthread_gettid.c
+35
-0
libc-test/src/functional/test_src_functional.gni
libc-test/src/functional/test_src_functional.gni
+1
-0
porting/linux/user/include/pthread.h
porting/linux/user/include/pthread.h
+1
-0
porting/linux/user/src/internal/pthread_impl.h
porting/linux/user/src/internal/pthread_impl.h
+1
-0
src/thread/pthread_create.c
src/thread/pthread_create.c
+39
-0
未找到文件。
libc-test/src/functional/pthread_gettid.c
0 → 100644
浏览文件 @
7d383b13
#include <pthread.h>
#include <string.h>
#include "test.h"
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#define TEST(c, ...) ((c) ? 1 : (t_error(#c" failed: " __VA_ARGS__),0))
static
pthread_mutex_t
mutex
;
void
*
pthread_test
(
void
*
arg
)
{
pthread_mutex_lock
(
&
mutex
);
*
((
pid_t
*
)
arg
)
=
gettid
();
pthread_mutex_unlock
(
&
mutex
);
return
NULL
;
}
int
main
(
int
argc
,
char
const
*
argv
[])
{
pthread_mutex_init
(
&
mutex
,
NULL
);
TEST
(
gettid
()
==
pthread_gettid
(
pthread_self
()),
"pthread_gettid() is failed
\n
"
);
pthread_mutex_lock
(
&
mutex
);
pid_t
tid
;
pthread_t
t
;
pthread_create
(
&
t
,
NULL
,
pthread_test
,
&
tid
);
pid_t
recv_result
=
pthread_gettid
(
t
);
TEST
(
0
==
pthread_join
(
t
,
NULL
),
"pthread_join is failed
\n
"
);
pthread_mutex_unlock
(
&
mutex
);
TEST
(
tid
==
recv_result
,
"the tid of pthread or tid of pthread_gettid is wrong
\n
"
);
return
0
;
}
\ No newline at end of file
libc-test/src/functional/test_src_functional.gni
浏览文件 @
7d383b13
...
...
@@ -23,6 +23,7 @@ functional_list = [
"pthread_cancel-points",
"pthread_cancel",
"pthread_cond",
"pthread_gettid",
"pthread_mutex",
"pthread_mutex_pi",
"pthread_robust",
...
...
porting/linux/user/include/pthread.h
浏览文件 @
7d383b13
...
...
@@ -96,6 +96,7 @@ int pthread_create(pthread_t *__restrict, const pthread_attr_t *__restrict, void
int
pthread_detach
(
pthread_t
);
_Noreturn
void
pthread_exit
(
void
*
);
int
pthread_join
(
pthread_t
,
void
**
);
pid_t
pthread_gettid
(
pthread_t
);
#ifdef __GNUC__
__attribute__
((
const
))
...
...
porting/linux/user/src/internal/pthread_impl.h
浏览文件 @
7d383b13
...
...
@@ -183,6 +183,7 @@ hidden void __inhibit_ptc(void);
hidden
void
__tl_lock
(
void
);
hidden
void
__tl_unlock
(
void
);
hidden
void
__tl_sync
(
pthread_t
);
hidden
struct
pthread
*
__pthread_list_find
(
pthread_t
,
const
char
*
);
extern
hidden
volatile
int
__thread_list_lock
;
...
...
src/thread/pthread_create.c
浏览文件 @
7d383b13
...
...
@@ -6,6 +6,15 @@
#include <sys/mman.h>
#include <string.h>
#include <stddef.h>
#include <stdarg.h>
void
log_print
(
const
char
*
info
,...)
{
va_list
ap
;
va_start
(
ap
,
info
);
vfprintf
(
stdout
,
info
,
ap
);
va_end
(
ap
);
}
static
void
dummy_0
()
{
...
...
@@ -380,3 +389,33 @@ fail:
weak_alias
(
__pthread_exit
,
pthread_exit
);
weak_alias
(
__pthread_create
,
pthread_create
);
struct
pthread
*
__pthread_list_find
(
pthread_t
thread_id
,
const
char
*
info
)
{
struct
pthread
*
thread
=
(
struct
pthread
*
)
thread_id
;
if
(
NULL
==
thread
)
{
log_print
(
"invalid pthread_t (0) passed to %s
\n
"
,
info
);
return
NULL
;
}
struct
pthread
*
self
=
__pthread_self
();
if
(
thread
==
self
)
{
return
thread
;
}
struct
pthread
*
t
=
self
;
t
=
t
->
next
;
while
(
t
!=
self
)
{
if
(
t
==
thread
)
return
thread
;
t
=
t
->
next
;
}
return
NULL
;
}
pid_t
__pthread_gettid
(
pthread_t
t
)
{
__tl_lock
();
struct
pthread
*
thread
=
__pthread_list_find
(
t
,
"pthread_gettid"
);
__tl_unlock
();
return
thread
?
thread
->
tid
:
-
1
;
}
weak_alias
(
__pthread_gettid
,
pthread_gettid
);
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录