diff --git a/ajalibraries/ajabase/system/linux/threadimpl.cpp b/ajalibraries/ajabase/system/linux/threadimpl.cpp index 12a72e9..66ae11a 100644 --- a/ajalibraries/ajabase/system/linux/threadimpl.cpp +++ b/ajalibraries/ajabase/system/linux/threadimpl.cpp @@ -538,6 +538,8 @@ AJAThreadImpl::ThreadProcStatic(void* pThreadImplContext) if (errno == 0) // theoretically gettid() cannot fail, so by extension syscall(SYS_gettid) can't either...? pThreadImpl->mTid = myTid; + if (pThreadImpl->mThreadName.size() > 0) + pthread_setname_np(pThreadImpl->mThread, pThreadImpl->mThreadName.c_str()); // signal parent we've started int rc = pthread_mutex_lock(&pThreadImpl->mStartMutex); @@ -609,11 +611,12 @@ AJAThreadImpl::ThreadProcStatic(void* pThreadImplContext) } AJAStatus AJAThreadImpl::SetThreadName(const char *name) { - int ret = prctl(PR_SET_NAME, (unsigned long)name, 0, 0); - if(ret == -1) { - AJA_REPORT(0, AJA_DebugSeverity_Error, "Failed to set thread name to %s", name); - return AJA_STATUS_FAIL; - } + AJAAutoLock lock(&mLock); + mThreadName = name; + if (mThreadName.size() > 15) + mThreadName.resize(15); + if (mThread > 0) + pthread_setname_np(mThread, mThreadName.c_str()); return AJA_STATUS_SUCCESS; } diff --git a/ajalibraries/ajabase/system/linux/threadimpl.h b/ajalibraries/ajabase/system/linux/threadimpl.h index 90202cc..892932b 100644 --- a/ajalibraries/ajabase/system/linux/threadimpl.h +++ b/ajalibraries/ajabase/system/linux/threadimpl.h @@ -13,6 +13,7 @@ #include "ajabase/common/common.h" #include "ajabase/system/thread.h" #include "ajabase/system/lock.h" +#include class AJAThreadImpl @@ -59,6 +60,8 @@ class AJAThreadImpl bool mExiting; pthread_mutex_t mExitMutex; pthread_cond_t mExitCond; + + std::string mThreadName; }; #endif // AJA_THREAD_IMPL_H