epicsShareFunc void epicsShareAPI epicsThreadSetPriority(epicsThreadId pthreadInfo,unsigned int priority) { #if defined (_POSIX_THREAD_PRIORITY_SCHEDULING) int status; #endif /* _POSIX_THREAD_PRIORITY_SCHEDULING */ assert(epicsThreadOnceCalled); assert(pthreadInfo); if(!pthreadInfo->isEpicsThread) { fprintf(stderr,"epicsThreadSetPriority called by non epics thread\n"); return; } pthreadInfo->osiPriority = priority; if(!pthreadInfo->isFifoScheduled) return; #if defined (_POSIX_THREAD_PRIORITY_SCHEDULING) if(!pcommonAttr->usePolicy) return; pthreadInfo->schedParam.sched_priority = getOssPriorityValue(pthreadInfo); status = pthread_attr_setschedparam( &pthreadInfo->attr,&pthreadInfo->schedParam); if(errVerbose) checkStatus(status,"pthread_attr_setschedparam"); status = pthread_setschedparam( pthreadInfo->tid,pcommonAttr->schedPolicy,&pthreadInfo->schedParam); if(errVerbose) checkStatus(status,"pthread_setschedparam"); #endif /* _POSIX_THREAD_PRIORITY_SCHEDULING */ }
/* called recursively */ #define checkStatusOnce(status,message) \ if((status)) {\ fprintf(stderr,"%s error %s\n",(message),strerror((status))); } #define checkStatusOnceQuit(status,message,method) \ if(status) { \ fprintf(stderr,"%s error %s",(message),strerror((status))); \ fprintf(stderr," %s\n",method); \ fprintf(stderr,"epicsThreadInit cant proceed. Program exiting\n"); \ exit(-1);\ } #if defined (_POSIX_THREAD_PRIORITY_SCHEDULING) static int getOssPriorityValue(epicsThreadOSD *pthreadInfo) { double maxPriority,minPriority,slope,oss; if(pcommonAttr->maxPriority==pcommonAttr->minPriority) return(pcommonAttr->maxPriority); maxPriority = (double)pcommonAttr->maxPriority; minPriority = (double)pcommonAttr->minPriority; slope = (maxPriority - minPriority)/100.0; oss = (double)pthreadInfo->osiPriority * slope + minPriority; return((int)oss); } #endif /* _POSIX_THREAD_PRIORITY_SCHEDULING */ static void setSchedulingPolicy(epicsThreadOSD *pthreadInfo,int policy) { #if defined (_POSIX_THREAD_PRIORITY_SCHEDULING) int status; status = pthread_attr_getschedparam( &pthreadInfo->attr,&pthreadInfo->schedParam); checkStatusOnce(status,"pthread_attr_getschedparam"); pthreadInfo->schedParam.sched_priority = getOssPriorityValue(pthreadInfo); status = pthread_attr_setschedpolicy( &pthreadInfo->attr,policy); checkStatusOnce(status,"pthread_attr_setschedpolicy"); status = pthread_attr_setschedparam( &pthreadInfo->attr,&pthreadInfo->schedParam); checkStatusOnce(status,"pthread_attr_setschedparam"); status = pthread_attr_setinheritsched( &pthreadInfo->attr,PTHREAD_EXPLICIT_SCHED); checkStatusOnce(status,"pthread_attr_setinheritsched"); #endif /* _POSIX_THREAD_PRIORITY_SCHEDULING */ }