Skip to content

Commit

Permalink
Merge pull request #1587 from dpogue/pthread_setname
Browse files Browse the repository at this point in the history
Detect pthread_setname_np with CMake
  • Loading branch information
dpogue committed May 30, 2024
2 parents 2627724 + 43d05e0 commit 419bd83
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
4 changes: 3 additions & 1 deletion Sources/Plasma/CoreLib/hsThread_Unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ int clock_gettime(int clocktype, struct timespec* ts)

void hsThread::SetThisThreadName(const ST::string& name)
{
#ifdef HAVE_PTHREAD_SETNAME_NP
#if defined(HS_BUILD_FOR_APPLE)
// The Apple version doesn't take a thread argument and always operates on the current thread.
int res = pthread_setname_np(name.c_str());
Expand All @@ -86,7 +87,8 @@ void hsThread::SetThisThreadName(const ST::string& name)
// On Linux, thread names must fit into 16 bytes, including the terminator.
int res = pthread_setname_np(pthread_self(), name.left(15).c_str());
hsAssert(res == 0, "Failed to set thread name");
#endif
#endif // HS_BUILD_FOR_LINUX
#endif // HAVE_PTHREAD_SETNAME_NP
// Because this is just a debugging help, do nothing by default (sorry, BSDs).
}

Expand Down
4 changes: 3 additions & 1 deletion cmake/CompilerChecks.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ if(NOT DEFINED CMAKE_INTERPROCEDURAL_OPTIMIZATION)
endif()
endif()

# Check for Linux sysinfo.
include(CheckCXXSymbolExists)
# Check for Linux sysinfo.
check_cxx_symbol_exists("sysinfo" "sys/sysinfo.h" HAVE_SYSINFO)
# Check for pthread setname_np API
check_cxx_symbol_exists(pthread_setname_np pthread.h HAVE_PTHREAD_SETNAME_NP)

# Check for BSD style sysctl.
try_compile(HAVE_SYSCTL ${PROJECT_BINARY_DIR}
Expand Down
1 change: 1 addition & 0 deletions cmake/hsConfig.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,6 @@ You can contact Cyan Worlds, Inc. by email [email protected]
#cmakedefine HAVE_SYSDIR
#cmakedefine HAVE_SYSINFO
#cmakedefine HAVE_SHELLSCALINGAPI
#cmakedefine HAVE_PTHREAD_SETNAME_NP

#endif

0 comments on commit 419bd83

Please sign in to comment.