bool CThread::SetPriority(const int iPriority) { bool bReturn = false; // 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 int minRR = GetMaxPriority() + 1; if (!m_ThreadId) bReturn = false; else if (iPriority >= minRR) bReturn = SetPrioritySched_RR(iPriority); #ifdef RLIMIT_NICE else { // get user max prio struct rlimit limit; int userMaxPrio; if (getrlimit(RLIMIT_NICE, &limit) == 0) { userMaxPrio = limit.rlim_cur - 20; // is a user has no entry in limits.conf rlim_cur is zero if (userMaxPrio < 0) userMaxPrio = 0; } else userMaxPrio = 0; if (geteuid() == 0) userMaxPrio = GetMaxPriority(); // keep priority in bounds int prio = iPriority; if (prio >= GetMaxPriority()) prio = std::min(GetMaxPriority(), userMaxPrio); if (prio < GetMinPriority()) prio = GetMinPriority(); // nice level of application int appNice = getpriority(PRIO_PROCESS, getpid()); if (prio) prio = prio > 0 ? appNice-1 : appNice+1; if (setpriority(PRIO_PROCESS, m_ThreadOpaque.LwpId, prio) == 0) bReturn = true; else if (logger) logger->Log(LOGERROR, "%s: error %s", __FUNCTION__, strerror(errno)); } #endif return bReturn; }
void CJobWorker::Process() { SetPriority( GetMinPriority() ); while (true) { // request an item from our manager (this call is blocking) CJob *job = m_jobManager->GetNextJob(this); if (!job) break; bool success = false; try { success = job->DoWork(); } catch (...) { CLog::Log(LOGERROR, "%s error processing job %s", __FUNCTION__, job->GetType()); } m_jobManager->OnJobComplete(success, job); } }
void CUdpClient::OnStartup() { SetPriority( GetMinPriority() ); }
void CLirc::Start() { Create(); SetPriority(GetMinPriority()); }
void CAddonStatusHandler::OnStartup() { SetPriority(GetMinPriority()); }