diff options
author | William Harrington <kb0iic@berzerkula.org> | 2025-01-14 16:06:02 -0600 |
---|---|---|
committer | William Harrington <kb0iic@berzerkula.org> | 2025-01-14 16:06:02 -0600 |
commit | 0cc9b20c15460213e488bf5e70963b941482f628 (patch) | |
tree | bb0143245583ec846630f39bfa2258dba640ccd7 /sdk/proc/priority.c | |
parent | 0e084ade5069756d487b5c948c48b777e37c00c9 (diff) |
Add source.
Diffstat (limited to 'sdk/proc/priority.c')
-rw-r--r-- | sdk/proc/priority.c | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/sdk/proc/priority.c b/sdk/proc/priority.c new file mode 100644 index 0000000..8818567 --- /dev/null +++ b/sdk/proc/priority.c @@ -0,0 +1,73 @@ +/* + * Specify process for soft realtime scheduling treatment. + * $Id$ + * Copyright (c) 1997 by Tycho Softworks. + * For conditions of distribution and reuse see product license. + */ + +#include <proc/process.h> +#include <std/time.h> + +#ifndef SYS_RESOURCE_H_MISSING +#include <sys/resource.h> +#endif + +#ifndef SETPRIORITY_F_MISSING + +int priority(int pri) +{ +#ifdef _POSIX_PRIORITY_SCHEDULING + #define _P __P + + #include <sched.h> + + struct sched_param p; +#endif + int newpri = getpriority(PRIO_PROCESS, 0) - pri - 1; + + if(setpriority(PRIO_PROCESS, 0, newpri)) + return -1; + +#ifdef _POSIX_MEMLOCK + #include <linux/mman.h> + + if(mlockall(MCL_CURRENT | MCL_FUTURE)) + return -1; +#endif + +#ifdef _POSIX_PRIORITY_SCHEDULING + if(pri > 0) + { + p.sched_priority = sched_get_priority_min(SCHED_RR) + pri - 1; + if(sched_setscheduler(0, SCHED_RR, &p)) + return -1; + } +#endif + + return 0; +} + +#else + +int priority(int priority) +{ + return nice(- priority - 1); +} +#endif + +#ifdef _POSIX_PRIORITY_SCHEDULING +#include <sched.h> + +void yield(void) +{ + sched_yield(); +} +#else + +void yield(void) +{ + sleep(0); +} +#endif + + |