Fix pthread_setname not declared (#4210)

* Fix pthread_setname not declared #4063

* Fix include prctl.h for specific OS #4063

* Fix getThreadName for specific OS #4063

---------

Co-authored-by: root <root@debian-gnu-linux-11.localdomain>
Co-authored-by: Pavle <pavle@debian-gnu-linux-11.localdomain>
This commit is contained in:
Pavle Dragisic 2023-10-23 08:17:51 +02:00 committed by GitHub
parent 5131fe1c15
commit c918c70e68
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -37,6 +37,10 @@
# include <time.h>
#endif
#if POCO_OS == POCO_OS_LINUX || POCO_OS == POCO_OS_ANDROID || POCO_OS == POCO_OS_FREE_BSD
# include <sys/prctl.h>
#endif
#if POCO_OS == POCO_OS_LINUX
#ifndef _GNU_SOURCE
#define _GNU_SOURCE /* See feature_test_macros(7) */
@ -83,7 +87,7 @@ namespace
#elif (POCO_OS == POCO_OS_MAC_OS_X)
if (pthread_setname_np(threadName.c_str()))
#else
if (pthread_setname_np(pthread_self(), threadName.c_str()))
if (prctl(PR_SET_NAME, threadName.c_str()))
#endif
throw Poco::SystemException("cannot set thread name");
}
@ -91,8 +95,13 @@ namespace
std::string getThreadName()
{
char name[POCO_MAX_THREAD_NAME_LEN + 1]{'\0'};
#if POCO_OS == POCO_OS_LINUX || POCO_OS == POCO_OS_ANDROID || POCO_OS == POCO_OS_FREE_BSD
if (prctl(PR_GET_NAME, name))
throw Poco::SystemException("cannot get thread name");
#else
if (pthread_getname_np(pthread_self(), name, POCO_MAX_THREAD_NAME_LEN + 1))
throw Poco::SystemException("cannot get thread name");
#endif
return name;
}
}