Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

threads: fix linux thread prio in case user has no entry in limits.conf

  • Loading branch information...
commit f5af55a37750f51f9dad42d162d71bb2b6b48e21 1 parent f7f77a7
@FernetMenta FernetMenta authored
Showing with 26 additions and 4 deletions.
  1. +26 −4 xbmc/threads/platform/pthreads/ThreadImpl.cpp
View
30 xbmc/threads/platform/pthreads/ThreadImpl.cpp
@@ -70,10 +70,29 @@ void CThread::SetThreadInfo()
#endif
#endif
- // start thread with nice level of appication
- int appNice = getpriority(PRIO_PROCESS, getpid());
- if (setpriority(PRIO_PROCESS, m_ThreadOpaque.LwpId, appNice) != 0)
- if (logger) logger->Log(LOGERROR, "%s: error %s", __FUNCTION__, strerror(errno));
+#ifdef RLIMIT_NICE
+ // get user max prio
+ struct rlimit limit;
+ int userMaxPrio;
+ if (getrlimit(RLIMIT_NICE, &limit) == 0)
+ {
+ userMaxPrio = limit.rlim_cur - 20;
+ if (userMaxPrio < 0)
+ userMaxPrio = 0;
+ }
+ else
+ userMaxPrio = 0;
+
+ // if the user does not have an entry in limits.conf the following
+ // call will fail
+ if (userMaxPrio > 0)
+ {
+ // start thread with nice level of appication
+ int appNice = getpriority(PRIO_PROCESS, getpid());
+ if (setpriority(PRIO_PROCESS, m_ThreadOpaque.LwpId, appNice) != 0)
+ if (logger) logger->Log(LOGERROR, "%s: error %s", __FUNCTION__, strerror(errno));
+ }
+#endif
}
ThreadIdentifier CThread::GetCurrentThreadId()
@@ -129,6 +148,9 @@ bool CThread::SetPriority(const int iPriority)
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;
Please sign in to comment.
Something went wrong with that request. Please try again.