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 <unistd.h> 8 #include <pthread.h> 9 #include <sys/syscall.h> 10 11 #include <rte_eal.h> 12 #include <rte_lcore.h> 13 #include <rte_string_fns.h> 14 15 /* require calling thread tid by gettid() */ 16 int rte_sys_gettid(void) 17 { 18 return (int)syscall(SYS_gettid); 19 } 20 21 int rte_thread_setname(pthread_t id, const char *name) 22 { 23 int ret = ENOSYS; 24 #if defined(__GLIBC__) && defined(__GLIBC_PREREQ) 25 #if __GLIBC_PREREQ(2, 12) 26 char truncated[16]; 27 28 strlcpy(truncated, name, sizeof(truncated)); 29 ret = pthread_setname_np(id, truncated); 30 #endif 31 #endif 32 RTE_SET_USED(id); 33 RTE_SET_USED(name); 34 return -ret; 35 } 36 37 int rte_thread_getname(pthread_t id, char *name, size_t len) 38 { 39 int ret = ENOSYS; 40 #if defined(__GLIBC__) && defined(__GLIBC_PREREQ) 41 #if __GLIBC_PREREQ(2, 12) 42 ret = pthread_getname_np(id, name, len); 43 #endif 44 #endif 45 RTE_SET_USED(id); 46 RTE_SET_USED(name); 47 RTE_SET_USED(len); 48 return -ret; 49 50 } 51