From 0cc9b20c15460213e488bf5e70963b941482f628 Mon Sep 17 00:00:00 2001 From: William Harrington Date: Tue, 14 Jan 2025 16:06:02 -0600 Subject: Add source. --- sdk/proc/priority.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 sdk/proc/priority.c (limited to 'sdk/proc/priority.c') 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 +#include + +#ifndef SYS_RESOURCE_H_MISSING +#include +#endif + +#ifndef SETPRIORITY_F_MISSING + +int priority(int pri) +{ +#ifdef _POSIX_PRIORITY_SCHEDULING + #define _P __P + + #include + + 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 + + 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 + +void yield(void) +{ + sched_yield(); +} +#else + +void yield(void) +{ + sleep(0); +} +#endif + + -- cgit v1.2.3-54-g00ecf