aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxbmc <fernetmenta@online.de>2012-07-14 09:35:16 +0200
committerxbmc <fernetmenta@online.de>2012-07-23 13:11:36 +0200
commitf5af55a37750f51f9dad42d162d71bb2b6b48e21 (patch)
tree537bc6b7f374b2bed52f78dae238a58e2772647c
parentf7f77a7afa094ff7c1cd8665e998fd7006148f71 (diff)
threads: fix linux thread prio in case user has no entry in limits.conf
-rw-r--r--xbmc/threads/platform/pthreads/ThreadImpl.cpp30
1 files changed, 26 insertions, 4 deletions
diff --git a/xbmc/threads/platform/pthreads/ThreadImpl.cpp b/xbmc/threads/platform/pthreads/ThreadImpl.cpp
index 6e49f4fcad..ec25bf999a 100644
--- a/xbmc/threads/platform/pthreads/ThreadImpl.cpp
+++ b/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;