aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpkerling <pkerling@casix.org>2018-03-16 15:09:04 +0000
committerGitHub <noreply@github.com>2018-03-16 15:09:04 +0000
commitb58a89cd81a3b2c5007fa9349ebbf2bc23fa35a9 (patch)
tree669732c0a019616023be2887b3006b9299c7d2da
parent3fd2f2ea9386b3b766546a6b0043e4d8bdba77e6 (diff)
parent7cf42a4820493dda221ce80661bf36e497519188 (diff)
Merge pull request #13569 from pkerling/pthread_setname
Fix thread naming on Linux and Darwin
-rw-r--r--cmake/scripts/linux/ArchSetup.cmake5
-rw-r--r--xbmc/threads/platform/pthreads/ThreadImpl.cpp18
2 files changed, 10 insertions, 13 deletions
diff --git a/cmake/scripts/linux/ArchSetup.cmake b/cmake/scripts/linux/ArchSetup.cmake
index 0632ca6117..45b1da709b 100644
--- a/cmake/scripts/linux/ArchSetup.cmake
+++ b/cmake/scripts/linux/ArchSetup.cmake
@@ -1,4 +1,5 @@
-set(ARCH_DEFINES -D_LINUX -DTARGET_POSIX -DTARGET_LINUX)
+# we always want to use GNU features if available, so set _GNU_SOURCE
+set(ARCH_DEFINES -D_LINUX -DTARGET_POSIX -DTARGET_LINUX -D_GNU_SOURCE)
# temp until further cleanup is done
if(CORE_PLATFORM_NAME_LC STREQUAL rbpi)
list(APPEND ARCH_DEFINES -D_ARMEL -DTARGET_RASPBERRY_PI)
@@ -83,7 +84,7 @@ set(CMAKE_REQUIRED_DEFINITIONS "-D_GNU_SOURCE")
check_symbol_exists("mkostemp" "stdlib.h" HAVE_MKOSTEMP)
set(CMAKE_REQUIRED_DEFINITIONS "")
if(HAVE_MKOSTEMP)
- list(APPEND ARCH_DEFINES "-DHAVE_MKOSTEMP=1" "-D_GNU_SOURCE")
+ list(APPEND ARCH_DEFINES "-DHAVE_MKOSTEMP=1")
endif()
# Additional SYSTEM_DEFINES
diff --git a/xbmc/threads/platform/pthreads/ThreadImpl.cpp b/xbmc/threads/platform/pthreads/ThreadImpl.cpp
index ecb51899c6..c9253f43b4 100644
--- a/xbmc/threads/platform/pthreads/ThreadImpl.cpp
+++ b/xbmc/threads/platform/pthreads/ThreadImpl.cpp
@@ -92,16 +92,12 @@ void CThread::SetThreadInfo()
m_ThreadOpaque.LwpId = syscall(SYS_gettid);
#endif
-#if defined(HAVE_PTHREAD_SETNAME_NP)
-#ifdef TARGET_DARWIN
+#if defined(TARGET_DARWIN)
pthread_setname_np(m_ThreadName.c_str());
-#else
+#elif defined(TARGET_LINUX) && defined(__GLIBC__)
pthread_setname_np(m_ThreadId, m_ThreadName.c_str());
#endif
-#elif defined(HAVE_PTHREAD_SET_NAME_NP)
- pthread_set_name_np(m_ThreadId, m_ThreadName.c_str());
-#endif
-
+
#ifdef RLIMIT_NICE
// get user max prio
struct rlimit limit;
@@ -164,7 +160,7 @@ bool CThread::SetPriority(const int iPriority)
// wait until thread is running, it needs to get its lwp id
m_StartEvent.Wait();
-
+
CSingleLock lock(m_CriticalSection);
// get min prio for SCHED_RR
@@ -223,7 +219,7 @@ int CThread::GetPriority()
m_StartEvent.Wait();
CSingleLock lock(m_CriticalSection);
-
+
int appNice = getpriority(PRIO_PROCESS, getpid());
int prio = getpriority(PRIO_PROCESS, m_ThreadOpaque.LwpId);
iReturn = appNice - prio;
@@ -241,10 +237,10 @@ bool CThread::WaitForThreadExit(unsigned int milliseconds)
int64_t CThread::GetAbsoluteUsage()
{
CSingleLock lock(m_CriticalSection);
-
+
if (!m_ThreadId)
return 0;
-
+
int64_t time = 0;
#ifdef TARGET_DARWIN
thread_basic_info threadInfo;