Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pthread_setname not declared #4210

Merged
merged 3 commits into from
Oct 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion Foundation/src/Thread_POSIX.cpp
Original file line number Diff line number Diff line change
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