aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRainer Hochecker <fernetmenta@online.de>2012-08-01 10:26:54 -0700
committerRainer Hochecker <fernetmenta@online.de>2012-08-01 10:26:54 -0700
commitc662ad2b9e30c7456aa8ff124454a5866581a052 (patch)
tree9d6d387e9a42a151c323602a686ea7bc299a096b
parent99f740784d184c5667177969d8d17176a7b733ec (diff)
parentf5af55a37750f51f9dad42d162d71bb2b6b48e21 (diff)
Merge pull request #1157 from FernetMenta/threadfix
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;