From 2bb443557d35ae748f7bfc9a3bcf711f1ca96048 Mon Sep 17 00:00:00 2001 From: James McDonnell Date: Tue, 24 Oct 2017 18:05:49 -0400 Subject: Create a QNX version of calculateUnixPriority The standard calculateUnixPriority provides values that are almost invariably inappropriate with even LowestPriority mapping to something higher than the priority of any other thread on the system. [ChangeLog][QtCore][QThread] Changed how Qt thread priorities are mapped to QNX system thread priorities. Task-number: QTBUG-53357 Change-Id: I205035c4ca7dcafabda7a9a9b06cc52c67c6d2b2 Reviewed-by: Thiago Macieira Reviewed-by: Olivier Goffart (Woboq GmbH) --- src/corelib/thread/qthread_unix.cpp | 54 +++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'src') diff --git a/src/corelib/thread/qthread_unix.cpp b/src/corelib/thread/qthread_unix.cpp index f839e4449b..fb5c9fd770 100644 --- a/src/corelib/thread/qthread_unix.cpp +++ b/src/corelib/thread/qthread_unix.cpp @@ -109,6 +109,10 @@ #define QT_HAS_THREAD_PRIORITY_SCHEDULING #endif +#if defined(Q_OS_QNX) +#include +#endif + QT_BEGIN_NAMESPACE @@ -552,6 +556,55 @@ void QThread::usleep(unsigned long usecs) } #ifdef QT_HAS_THREAD_PRIORITY_SCHEDULING +#if defined(Q_OS_QNX) +static bool calculateUnixPriority(int priority, int *sched_policy, int *sched_priority) +{ + // On QNX, NormalPriority is mapped to 10. A QNX system could use a value different + // than 10 for the "normal" priority but it's difficult to achieve this so we'll + // assume that no one has ever created such a system. This makes the mapping from + // Qt priorities to QNX priorities lopsided. There's usually more space available + // to map into above the "normal" priority than below it. QNX also has a privileged + // priority range (for threads that assist the kernel). We'll assume that no Qt + // thread needs to use priorities in that range. + int priority_norm = 10; + // _sched_info::priority_priv isn't documented. You'd think that it's the start of the + // privileged priority range but it's actually the end of the unpriviledged range. + struct _sched_info info; + if (SchedInfo_r(0, *sched_policy, &info) != EOK) + return false; + + if (priority == QThread::IdlePriority) { + *sched_priority = info.priority_min; + return true; + } + + if (priority_norm < info.priority_min) + priority_norm = info.priority_min; + if (priority_norm > info.priority_priv) + priority_norm = info.priority_priv; + + int to_min, to_max; + int from_min, from_max; + int prio; + if (priority < QThread::NormalPriority) { + to_min = info.priority_min; + to_max = priority_norm; + from_min = QThread::LowestPriority; + from_max = QThread::NormalPriority; + } else { + to_min = priority_norm; + to_max = info.priority_priv; + from_min = QThread::NormalPriority; + from_max = QThread::TimeCriticalPriority; + } + + prio = ((priority - from_min) * (to_max - to_min)) / (from_max - from_min) + to_min; + prio = qBound(to_min, prio, to_max); + + *sched_priority = prio; + return true; +} +#else // Does some magic and calculate the Unix scheduler priorities // sched_policy is IN/OUT: it must be set to a valid policy before calling this function // sched_priority is OUT only @@ -595,6 +648,7 @@ static bool calculateUnixPriority(int priority, int *sched_policy, int *sched_pr return true; } #endif +#endif void QThread::start(Priority priority) { -- cgit v1.2.3