diff --git a/headers/posix/pthread.h b/headers/posix/pthread.h index 7c79e99a21..8c2f436c5e 100644 --- a/headers/posix/pthread.h +++ b/headers/posix/pthread.h @@ -229,14 +229,14 @@ extern int pthread_attr_getscope(const pthread_attr_t *attr, int *contentionScope); extern int pthread_attr_setscope(pthread_attr_t *attr, int contentionScope); -#if 0 /* Unimplemented attribute functions: */ - /* mandatory! */ extern int pthread_attr_getschedparam(const pthread_attr_t *attr, struct sched_param *param); extern int pthread_attr_setschedparam(pthread_attr_t *attr, const struct sched_param *param); +#if 0 /* Unimplemented attribute functions: */ + /* [TPS] */ extern int pthread_attr_getinheritsched(const pthread_attr_t *attr, int *inheritsched); diff --git a/headers/posix/sched.h b/headers/posix/sched.h index 679dc2447a..b4fb4c5efe 100644 --- a/headers/posix/sched.h +++ b/headers/posix/sched.h @@ -1,5 +1,5 @@ /* - * Copyright 2008, Haiku Inc. All rights reserved. + * Copyright 2008-2009, Haiku Inc. All rights reserved. * Distributed under the terms of the MIT license. */ #ifndef _SCHED_H_ @@ -9,7 +9,17 @@ extern "C" { #endif +#define SCHED_OTHER 1 +#define SCHED_RR 2 +#define SCHED_FIFO 4 + +struct sched_param { + int sched_priority; +}; + extern int sched_yield(void); +extern int sched_get_priority_min(int); +extern int sched_get_priority_max(int); #ifdef __cplusplus } diff --git a/src/system/libroot/posix/pthread/pthread_attr.c b/src/system/libroot/posix/pthread/pthread_attr.c index 7ffc1c87aa..559040eca2 100644 --- a/src/system/libroot/posix/pthread/pthread_attr.c +++ b/src/system/libroot/posix/pthread/pthread_attr.c @@ -13,7 +13,6 @@ #include - int pthread_attr_init(pthread_attr_t *_attr) { @@ -134,3 +133,26 @@ pthread_attr_setscope(pthread_attr_t *attr, int contentionScope) return 0; } + +int +pthread_attr_setschedparam(pthread_attr_t *attr, const struct sched_param *param) +{ + if (attr == NULL || param == NULL) + return EINVAL; + + (*attr)->sched_priority = param->sched_priority; + + return 0; +} + +int +pthread_attr_getschedparam(const pthread_attr_t *attr, struct sched_param *param) +{ + if (attr == NULL || param == NULL) + return EINVAL; + + param->sched_priority = (*attr)->sched_priority; + + return 0; +} + diff --git a/src/system/libroot/posix/scheduler.cpp b/src/system/libroot/posix/scheduler.cpp index ea88da6224..5f33a3d18d 100644 --- a/src/system/libroot/posix/scheduler.cpp +++ b/src/system/libroot/posix/scheduler.cpp @@ -1,10 +1,14 @@ /* + * Copyright 2009, Michael Franz * Copyright 2008, Andreas Färber, andreas.faerber@web.de * Distributed under the terms of the MIT license. */ +#include #include +#include + #include @@ -15,3 +19,32 @@ sched_yield(void) return 0; } + +int +sched_get_priority_min(int policy) +{ + switch (policy) { + case SCHED_FIFO: + case SCHED_RR: + case SCHED_OTHER: + return B_LOW_PRIORITY; + default: + errno = EINVAL; + return -1; + } +} + + +int +sched_get_priority_max(int policy) +{ + switch (policy) { + case SCHED_FIFO: + case SCHED_RR: + case SCHED_OTHER: + return B_REAL_TIME_PRIORITY; + default: + errno = EINVAL; + return -1; + } +}