xref: /dpdk/lib/eal/linux/eal_thread.c (revision 592ab76f9f0f41993bebb44da85c37750a93ece9)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2014 Intel Corporation
3  */
4 
5 #include <errno.h>
6 #include <stdio.h>
7 #include <stdint.h>
8 #include <unistd.h>
9 #include <pthread.h>
10 #include <sys/syscall.h>
11 
12 #include <rte_debug.h>
13 #include <rte_launch.h>
14 #include <rte_log.h>
15 #include <rte_eal.h>
16 #include <rte_lcore.h>
17 #include <rte_string_fns.h>
18 
19 #include "eal_private.h"
20 #include "eal_thread.h"
21 
22 /* require calling thread tid by gettid() */
23 int rte_sys_gettid(void)
24 {
25 	return (int)syscall(SYS_gettid);
26 }
27 
28 int rte_thread_setname(pthread_t id, const char *name)
29 {
30 	int ret = ENOSYS;
31 #if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
32 #if __GLIBC_PREREQ(2, 12)
33 	char truncated[16];
34 
35 	strlcpy(truncated, name, sizeof(truncated));
36 	ret = pthread_setname_np(id, truncated);
37 #endif
38 #endif
39 	RTE_SET_USED(id);
40 	RTE_SET_USED(name);
41 	return -ret;
42 }
43 
44 int rte_thread_getname(pthread_t id, char *name, size_t len)
45 {
46 	int ret = ENOSYS;
47 #if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
48 #if __GLIBC_PREREQ(2, 12)
49 	ret = pthread_getname_np(id, name, len);
50 #endif
51 #endif
52 	RTE_SET_USED(id);
53 	RTE_SET_USED(name);
54 	RTE_SET_USED(len);
55 	return -ret;
56 
57 }
58