summaryrefslogtreecommitdiff
path: root/pthread_setschedparam.c
diff options
context:
space:
mode:
authorrpj <rpj>2003-09-18 02:31:39 +0000
committerrpj <rpj>2003-09-18 02:31:39 +0000
commitaf1871fba4fc253b5a31e4a0eed667fe79f534d7 (patch)
tree1242599d7334ae50c5c05f9b23b52876e4287924 /pthread_setschedparam.c
parentfac679912b15dd89cafdb09bf873d7eacc80a05e (diff)
Cleanup and fixes to thread priority management. Other minor changes.snap-2003-09-18
Diffstat (limited to 'pthread_setschedparam.c')
-rw-r--r--pthread_setschedparam.c55
1 files changed, 50 insertions, 5 deletions
diff --git a/pthread_setschedparam.c b/pthread_setschedparam.c
index 1741197..1447c04 100644
--- a/pthread_setschedparam.c
+++ b/pthread_setschedparam.c
@@ -42,7 +42,6 @@ int
pthread_setschedparam(pthread_t thread, int policy,
const struct sched_param *param)
{
- int prio;
int result;
/* Validate the thread id. */
@@ -64,7 +63,17 @@ pthread_setschedparam(pthread_t thread, int policy,
return ENOTSUP;
}
- prio = param->sched_priority;
+ return (ptw32_setthreadpriority(thread, policy, param->sched_priority));
+}
+
+
+int
+ptw32_setthreadpriority(pthread_t thread, int policy, int priority)
+{
+ int prio;
+ int result;
+
+ prio = priority;
/* Validate priority level. */
if (prio < sched_get_priority_min(policy) ||
@@ -73,8 +82,44 @@ pthread_setschedparam(pthread_t thread, int policy,
return EINVAL;
}
- /* This is practically guaranteed to return TRUE. */
- (void) SetThreadPriority(thread->threadH, prio);
+#if (THREAD_PRIORITY_LOWEST > THREAD_PRIORITY_NORMAL)
+/* WinCE */
+#else
+/* Everything else */
+
+ if (THREAD_PRIORITY_IDLE < prio
+ && THREAD_PRIORITY_LOWEST > prio)
+ {
+ prio = THREAD_PRIORITY_LOWEST;
+ }
+ else if (THREAD_PRIORITY_TIME_CRITICAL > prio
+ && THREAD_PRIORITY_HIGHEST < prio)
+ {
+ prio = THREAD_PRIORITY_HIGHEST;
+ }
+
+#endif
+
+ result = pthread_mutex_lock(&thread->threadLock);
+
+ if (0 == result)
+ {
+ /* If this fails, the current priority is unchanged. */
+ if (0 == SetThreadPriority(thread->threadH, prio))
+ {
+ result = EINVAL;
+ }
+ else
+ {
+ /*
+ * Must record the thread's sched_priority as given,
+ * not as finally adjusted.
+ */
+ thread->sched_priority = priority;
+ }
+
+ (void) pthread_mutex_unlock(&thread->threadLock);
+ }
- return 0;
+ return result;
}