Patch from Michael Franz (ticket #4696): sched.h and pthreads to allow setting of the thread priority

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33783 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval 2009-10-26 22:56:43 +00:00
parent 4c091ffef4
commit f386c5910b
4 changed files with 69 additions and 4 deletions

View File

@ -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);

View File

@ -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
}

View File

@ -13,7 +13,6 @@
#include <thread_defs.h>
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;
}

View File

@ -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 <errno.h>
#include <sched.h>
#include <OS.h>
#include <syscalls.h>
@ -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;
}
}