Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Musl
提交
d401fc4c
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d401fc4c
编写于
7月 04, 2022
作者:
F
fangting
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
pthread_getname_np.c接口补充
Signed-off-by:
N
fangting
<
fangting10@huawei.com
>
上级
e6587537
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
82 addition
and
0 deletion
+82
-0
libc-test/src/functional/pthread_getname_np.c
libc-test/src/functional/pthread_getname_np.c
+49
-0
libc-test/src/functional/test_src_functional.gni
libc-test/src/functional/test_src_functional.gni
+1
-0
musl_src.gni
musl_src.gni
+2
-0
porting/linux/user/include/pthread.h
porting/linux/user/include/pthread.h
+1
-0
porting/linux/user/src/thread/pthread_getname_np.c
porting/linux/user/src/thread/pthread_getname_np.c
+29
-0
未找到文件。
libc-test/src/functional/pthread_getname_np.c
0 → 100644
浏览文件 @
d401fc4c
#define _GNU_SOURCE
#include <pthread.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <stdlib.h>
#define NAMELEN 16
#define errExitEN(en, msg) \
do
{
errno
=
en
;
perror
(
msg
);
exit
(
EXIT_FAILURE
);
\
}
while
(
0
)
static
void
*
threadfunc
(
void
*
parm
)
{
sleep
(
5
);
// allow main program to set the thread name
return
NULL
;
}
int
main
(
int
argc
,
char
**
argv
)
{
pthread_t
thread
;
int
rc
;
char
thread_name
[
NAMELEN
];
char
set_thread_name
[]
=
"THREADFOO"
;
char
default_name
[]
=
"pthread_getname_np"
;
rc
=
pthread_getname_np
(
pthread_self
(),
thread_name
,
NAMELEN
);
if
(
rc
!=
0
)
errExitEN
(
rc
,
"pthread_getname_np failed"
);
if
(
strcmp
(
thread_name
,
default_name
)
!=
0
)
perror
(
"pthread name comparison failed"
);
rc
=
pthread_create
(
&
thread
,
NULL
,
threadfunc
,
NULL
);
if
(
rc
!=
0
)
errExitEN
(
rc
,
"pthread_create failed"
);
rc
=
pthread_setname_np
(
thread
,
(
argc
>
1
)
?
argv
[
1
]
:
set_thread_name
);
if
(
rc
!=
0
)
errExitEN
(
rc
,
"pthread_setname_np failed"
);
sleep
(
2
);
rc
=
pthread_getname_np
(
thread
,
thread_name
,
(
argc
>
2
)
?
atoi
(
argv
[
1
])
:
NAMELEN
);
if
(
rc
!=
0
)
errExitEN
(
rc
,
"pthread_getname_np failed"
);
if
(
strcmp
(
thread_name
,
set_thread_name
)
!=
0
)
perror
(
"pthread name comparison failed"
);
rc
=
pthread_join
(
thread
,
NULL
);
if
(
rc
!=
0
)
errExitEN
(
rc
,
"pthread_join failed"
);
exit
(
EXIT_SUCCESS
);
}
\ No newline at end of file
libc-test/src/functional/test_src_functional.gni
浏览文件 @
d401fc4c
...
@@ -29,6 +29,7 @@ functional_list = [
...
@@ -29,6 +29,7 @@ functional_list = [
"pthread_mutex_pi",
"pthread_mutex_pi",
"pthread_robust",
"pthread_robust",
"pthread_tsd",
"pthread_tsd",
"pthread_getname_np",
"qsort",
"qsort",
"random",
"random",
"search_hsearch",
"search_hsearch",
...
...
musl_src.gni
浏览文件 @
d401fc4c
...
@@ -1293,6 +1293,7 @@ musl_src_file = [
...
@@ -1293,6 +1293,7 @@ musl_src_file = [
"src/thread/pthread_getattr_np.c",
"src/thread/pthread_getattr_np.c",
"src/thread/pthread_getconcurrency.c",
"src/thread/pthread_getconcurrency.c",
"src/thread/pthread_getcpuclockid.c",
"src/thread/pthread_getcpuclockid.c",
"src/thread/pthread_getname_np.c",
"src/thread/pthread_getschedparam.c",
"src/thread/pthread_getschedparam.c",
"src/thread/pthread_getspecific.c",
"src/thread/pthread_getspecific.c",
"src/thread/pthread_join.c",
"src/thread/pthread_join.c",
...
@@ -1939,6 +1940,7 @@ musl_src_porting_file = [
...
@@ -1939,6 +1940,7 @@ musl_src_porting_file = [
"src/time/strftime.c",
"src/time/strftime.c",
"src/time/strptime.c",
"src/time/strptime.c",
"src/time/time_impl.h",
"src/time/time_impl.h",
"src/thread/pthread_getname_np.c",
]
]
musl_inc_hook_files = [
musl_inc_hook_files = [
...
...
porting/linux/user/include/pthread.h
浏览文件 @
d401fc4c
...
@@ -395,6 +395,7 @@ int pthread_getaffinity_np(pthread_t, size_t, struct cpu_set_t *);
...
@@ -395,6 +395,7 @@ int pthread_getaffinity_np(pthread_t, size_t, struct cpu_set_t *);
int
pthread_setaffinity_np
(
pthread_t
,
size_t
,
const
struct
cpu_set_t
*
);
int
pthread_setaffinity_np
(
pthread_t
,
size_t
,
const
struct
cpu_set_t
*
);
int
pthread_getattr_np
(
pthread_t
,
pthread_attr_t
*
);
int
pthread_getattr_np
(
pthread_t
,
pthread_attr_t
*
);
int
pthread_setname_np
(
pthread_t
,
const
char
*
);
int
pthread_setname_np
(
pthread_t
,
const
char
*
);
int
pthread_getname_np
(
pthread_t
,
char
*
,
size_t
);
int
pthread_getattr_default_np
(
pthread_attr_t
*
);
int
pthread_getattr_default_np
(
pthread_attr_t
*
);
int
pthread_setattr_default_np
(
const
pthread_attr_t
*
);
int
pthread_setattr_default_np
(
const
pthread_attr_t
*
);
int
pthread_tryjoin_np
(
pthread_t
,
void
**
);
int
pthread_tryjoin_np
(
pthread_t
,
void
**
);
...
...
porting/linux/user/src/thread/pthread_getname_np.c
0 → 100644
浏览文件 @
d401fc4c
#define _GNU_SOURCE
#include <fcntl.h>
#include <unistd.h>
#include <sys/prctl.h>
#include "pthread_impl.h"
int
pthread_getname_np
(
pthread_t
thread
,
char
*
name
,
size_t
len
)
{
int
fd
,
cs
,
status
=
0
;
char
f
[
sizeof
"/proc/self/task//comm"
+
3
*
sizeof
(
int
)];
if
(
len
<
16
)
return
ERANGE
;
if
(
thread
==
pthread_self
())
return
prctl
(
PR_GET_NAME
,
(
unsigned
long
)
name
,
0UL
,
0UL
,
0UL
)
?
errno
:
0
;
snprintf
(
f
,
sizeof
f
,
"/proc/self/task/%d/comm"
,
thread
->
tid
);
pthread_setcancelstate
(
PTHREAD_CANCEL_DISABLE
,
&
cs
);
if
((
fd
=
open
(
f
,
O_RDONLY
|
O_CLOEXEC
))
<
0
||
(
len
=
read
(
fd
,
name
,
len
))
<
0
)
status
=
errno
;
else
name
[
len
-
1
]
=
0
;
/* remove trailing new line only if successful*/
/*It seems that Linux indeed always adds a newline, so removing it
unconditionally seems fine.*/
if
(
fd
>=
0
)
close
(
fd
);
pthread_setcancelstate
(
cs
,
0
);
return
status
;
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录