13 #include <sys/resource.h>
29 if (pthread_tryjoin_np(thread, &exitValue) != 0)
37 if (!pthread_kill(thread, 0))
46 mpThreadContext(pThreadContext),
52 mThreadStarted(
false),
131 rc |= pthread_attr_init(&attr);
132 rc |= pthread_attr_setstacksize(&attr,
STACK_SIZE);
133 rc |= pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
175 "AJAThread(%p)::Start pthread_cond_wait returned error %d",
186 "AJAThread(%p)::Start error %d unlocking start mutex",
191 #if 0 // This should be set within the running thread itself if a dynamic change
232 if (timeout == 0xffffffff)
234 ts.tv_sec += 60 * 60 * 24 * 365;
240 uint32_t nsec = ((timeout % 1000) * 1000000);
252 ts.tv_sec += (timeout / 1000) + (nsec / 1000000000);
253 ts.tv_nsec = (nsec % 1000000000);
271 "AJAThread(%p)::Stop pthread_cond_timedwait returned error %d",
283 "AJAThread(%p)::Stop error %d unlocking timeout mutex",
303 "AJAThread(%p)::Stop error %d unlocking exit mutex",
313 rc = pthread_join(
mThread, &exitValue);
320 "AJAThread(%p)::Stop error %d from pthread_join",
345 int rc = pthread_setcancelstate(PTHREAD_CANCEL_ENABLE,
NULL);
352 "AJAThread(%p)::Kill error %d from pthread_setcancelstate",
355 rc = pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS,
NULL);
362 "AJAThread(%p)::Kill error %d from pthread_setcanceltype",
374 "AJAThread(%p)::Kill error %d from pthread_cancel",
414 if( pthread_equal(
mThread, pthread_self()) )
445 bool bRTPriority =
false;
448 switch (threadPriority)
477 struct sched_param newParam;
478 newParam.sched_priority = (bRTPriority ? newPriority : 0);
479 int newPolicy = (bRTPriority ? SCHED_RR : SCHED_OTHER);
480 int rc = pthread_setschedparam(
mThread, newPolicy, &newParam);
488 int newNice = (bRTPriority ? 0 : newPriority);
489 rc = setpriority(PRIO_PROCESS,
mTid, newNice);
507 if (pThreadPriority ==
NULL)
539 for(
int i = 0; i < 30; i++)
546 struct sched_param newParam;
547 memset(&newParam, 0,
sizeof(newParam));
548 newParam.sched_priority = priority;
549 int rc = pthread_setschedparam(
mThread, pval, &newParam);
587 if (pThreadImpl ==
NULL)
595 pid_t myTid = syscall( SYS_gettid );
597 pThreadImpl->
mTid = myTid;
601 int rc = pthread_mutex_lock(&pThreadImpl->
mStartMutex);
610 rc = pthread_cond_signal(&pThreadImpl->
mStartCond);
616 rc = pthread_mutex_unlock(&pThreadImpl->
mStartMutex);
647 rc = pthread_mutex_lock(&pThreadImpl->
mExitMutex);
653 rc = pthread_cond_signal(&pThreadImpl->
mExitCond);
659 rc = pthread_mutex_unlock(&pThreadImpl->
mExitMutex);
674 int ret = prctl(PR_SET_NAME, (
unsigned long)name, 0, 0);
689 pid_t tid = syscall(SYS_gettid);
691 return uint64_t(tid);