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 thread naming on Linux and Darwin #13569

Merged
merged 1 commit into from Mar 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions 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)
Expand Down Expand Up @@ -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
Expand Down
18 changes: 7 additions & 11 deletions xbmc/threads/platform/pthreads/ThreadImpl.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down