diff options
author | bje <bje> | 1998-07-23 15:20:22 +0000 |
---|---|---|
committer | bje <bje> | 1998-07-23 15:20:22 +0000 |
commit | b9850298857209b12d9b7eacdb7bfe611f2dd57a (patch) | |
tree | 3b9ebe5ea427f29af38438de8fa49e9ad6597739 /sched.c | |
parent | 36dfdefb2c77879ceeef04e0b1094e5498b81b46 (diff) |
1998-07-24 Ben Elliston <bje@cygnus.com>
* sched.c (pthread_setschedparam): Implement.
(pthread_getschedparam): Implement.
(sched_get_priority_max): Validate policy argument.
(sched_get_priority_min): Likewise.
Diffstat (limited to 'sched.c')
-rw-r--r-- | sched.c | 74 |
1 files changed, 74 insertions, 0 deletions
@@ -32,14 +32,88 @@ int pthread_attr_getschedparam(const pthread_attr_t *attr, return 0; } +int pthread_setschedparam(pthread_t thread, int policy, + const struct sched_param *param) +{ + /* Validate the thread id. */ + if (_pthread_find_thread_entry(thread) < 0) + { + return EINVAL; + } + + /* Validate the scheduling policy. */ + if (policy < SCHED_MIN || policy > SCHED_MAX) + { + return EINVAL; + } + + /* Ensure the policy is SCHED_OTHER. */ + if (policy != SCHED_OTHER) + { + return ENOSUP; + } + + /* Validate priority level. */ + if (param->sched_policy < sched_get_priority_min(policy) || + param->sched_policy > sched_get_priority_max(policy)) + { + return EINVAL; + } + + /* This is practically guaranteed to return TRUE. */ + (void) SetThreadPriority(thread, param->sched_policy); + return 0; +} + +int pthread_getschedparam(pthread_t thread, int *policy, + struct sched_param *param) +{ + int prio; + + /* Validate the thread id. */ + if (_pthread_find_thread_entry(thread) < 0) + { + return EINVAL; + } + + /* Validate the param structure. */ + if (param == NULL) + { + return EINVAL; + } + + /* Fill out the policy. */ + *policy = SCHED_OTHER; + + /* Fill out the sched_param structure. */ + prio = GetThreadPriority(thread); + if (prio == THREAD_PRIORITY_ERROR_RETURN) + { + return EINVAL; + } + + param->sched_policy = prio; + return 0; +} + int sched_get_priority_max(int policy) { + if (policy < SCHED_MIN || policy > SCHED_MAX) + { + return EINVAL; + } + /* This is independent of scheduling policy in Win32. */ return THREAD_PRIORITY_HIGHEST; } int sched_get_priority_min(int policy) { + if (policy < SCHED_MIN || policy > SCHED_MAX) + { + return EINVAL; + } + /* This is independent of scheduling policy in Win32. */ return THREAD_PRIORITY_LOWEST; } |