void Thread::setPriority(Priority pr) { if(pr.validate()==false) errorHandler(INVALID_PARAMETERS); PauseKernelLock lock; Thread *current=getCurrentThread(); //If thread is locking at least one mutex if(current->mutexLocked!=0) { //savedPriority always changes, since when all mutexes are unlocked //setPriority() must become effective if(current->savedPriority==pr) return; current->savedPriority=pr; //Calculate new priority of thread, which is //max(savedPriority, inheritedPriority) Mutex *walk=current->mutexLocked; while(walk!=0) { if(walk->waiting.empty()==false) pr=std::max(pr,walk->waiting.front()->getPriority()); walk=walk->next; } } //If old priority == desired priority, nothing to do. if(pr==current->getPriority()) return; Scheduler::PKsetPriority(current,pr); #ifdef SCHED_TYPE_EDF if(isKernelRunning()) yield(); //Another thread might have a closer deadline #endif //SCHED_TYPE_EDF }