Permalink
Browse files

[droid] fixed linux thread priorities, do not mix xbmc priority level…

…s with system priority levels
  • Loading branch information...
1 parent 95e4224 commit 02b7a0c8e0990893dc969bc502f36dd855ff314a @davilla davilla committed with Cory Fields Jul 8, 2012
Showing with 40 additions and 28 deletions.
  1. +0 −14 xbmc/linux/PlatformDefs.h
  2. +16 −0 xbmc/threads/Thread.h
  3. +24 −14 xbmc/threads/platform/pthreads/ThreadImpl.cpp
View
@@ -313,20 +313,6 @@ typedef struct _TIME_ZONE_INFORMATION {
#define TIME_ZONE_ID_STANDARD 1
#define TIME_ZONE_ID_DAYLIGHT 2
-// Thread
-#define THREAD_BASE_PRIORITY_LOWRT 15
-#define THREAD_BASE_PRIORITY_MAX 2
-#define THREAD_BASE_PRIORITY_MIN -2
-#define THREAD_BASE_PRIORITY_IDLE -15
-#define THREAD_PRIORITY_LOWEST THREAD_BASE_PRIORITY_MIN
-#define THREAD_PRIORITY_BELOW_NORMAL (THREAD_PRIORITY_LOWEST+1)
-#define THREAD_PRIORITY_NORMAL 0
-#define THREAD_PRIORITY_HIGHEST THREAD_BASE_PRIORITY_MAX
-#define THREAD_PRIORITY_ABOVE_NORMAL (THREAD_PRIORITY_HIGHEST-1)
-#define THREAD_PRIORITY_ERROR_RETURN (0x7fffffff)
-#define THREAD_PRIORITY_TIME_CRITICAL THREAD_BASE_PRIORITY_LOWRT
-#define THREAD_PRIORITY_IDLE THREAD_BASE_PRIORITY_IDLE
-
// Network
#define SOCKADDR_IN struct sockaddr_in
#define IN_ADDR struct in_addr
View
@@ -36,6 +36,22 @@
#include <mach/mach.h>
#endif
+// Thread
+#if !defined(WIN32)
+#define THREAD_BASE_PRIORITY_LOWRT 15
+#define THREAD_BASE_PRIORITY_MAX 2
+#define THREAD_BASE_PRIORITY_MIN -2
+#define THREAD_BASE_PRIORITY_IDLE -15
+#define THREAD_PRIORITY_LOWEST THREAD_BASE_PRIORITY_MIN
+#define THREAD_PRIORITY_BELOW_NORMAL (THREAD_PRIORITY_LOWEST+1)
+#define THREAD_PRIORITY_NORMAL 0
+#define THREAD_PRIORITY_HIGHEST THREAD_BASE_PRIORITY_MAX
+#define THREAD_PRIORITY_ABOVE_NORMAL (THREAD_PRIORITY_HIGHEST-1)
+#define THREAD_PRIORITY_ERROR_RETURN (0x7fffffff)
+#define THREAD_PRIORITY_TIME_CRITICAL THREAD_BASE_PRIORITY_LOWRT
+#define THREAD_PRIORITY_IDLE THREAD_BASE_PRIORITY_IDLE
+#endif
+
class IRunnable
{
public:
@@ -115,39 +115,48 @@ bool CThread::IsCurrentThread(const ThreadIdentifier tid)
int CThread::GetMinPriority(void)
{
- // one level lower than application
- return -1;
+ return -4;
+ //return THREAD_PRIORITY_IDLE;
}
int CThread::GetMaxPriority(void)
{
- // one level higher than application
- return 1;
+ return 4;
+// return THREAD_PRIORITY_HIGHEST;
}
int CThread::GetNormalPriority(void)
{
- // same level as application
- return 0;
+ return THREAD_PRIORITY_NORMAL;
}
bool CThread::SetPriority(const int iPriority)
{
+ // iPriority is with respect to that defined in Thread.h
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
+ return false;
+
+ // keep priority in bounds
+ int prio = iPriority;
+ if (prio >= GetMaxPriority())
+ prio = GetMaxPriority();
+ if (prio < GetMinPriority())
+ prio = GetMinPriority();
+
+ // nice level of application
+ int appNice = getpriority(PRIO_PROCESS, getpid());
+ // flip it with respect to the 'nice' levels (-20 to 19)
+ prio = appNice - prio;
+
+ if (setpriority(PRIO_PROCESS, m_ThreadOpaque.LwpId, prio) == 0)
+ bReturn = true;
else
{
// get user max prio
@@ -180,7 +189,6 @@ bool CThread::SetPriority(const int iPriority)
else
if (logger) logger->Log(LOGERROR, "%s: error %s", __FUNCTION__, strerror(errno));
}
-#endif
return bReturn;
}
@@ -196,6 +204,8 @@ int CThread::GetPriority()
int appNice = getpriority(PRIO_PROCESS, getpid());
int prio = getpriority(PRIO_PROCESS, m_ThreadOpaque.LwpId);
+ // flip it with respect to the 'nice' levels (-20 to 19), so that
+ // what is returned is with repect to that defined in Thread.h
iReturn = appNice - prio;
return iReturn;

0 comments on commit 02b7a0c

Please sign in to comment.