Skip to content

Commit

Permalink
Fix pthread_setname not declared (#4210)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
3 people authored and aleks-f committed Nov 23, 2023
1 parent 818ddf6 commit fde8755
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Foundation/src/Thread_POSIX.cpp
Expand Up @@ -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) */
Expand Down Expand Up @@ -83,16 +87,21 @@ 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");
}

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;
}
}
Expand Down

0 comments on commit fde8755

Please sign in to comment.