Serenity Operating System
at master 57 lines 1.6 kB view raw
1/* 2 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7#include <errno.h> 8#include <sched.h> 9#include <syscall.h> 10 11extern "C" { 12 13// https://pubs.opengroup.org/onlinepubs/9699919799/functions/sched_yield.html 14int sched_yield() 15{ 16 int rc = syscall(SC_yield); 17 __RETURN_WITH_ERRNO(rc, rc, -1); 18} 19 20// https://pubs.opengroup.org/onlinepubs/9699919799/functions/sched_get_priority_min.html 21int sched_get_priority_min([[maybe_unused]] int policy) 22{ 23 return THREAD_PRIORITY_MIN; 24} 25 26// https://pubs.opengroup.org/onlinepubs/9699919799/functions/sched_get_priority_max.html 27int sched_get_priority_max([[maybe_unused]] int policy) 28{ 29 return THREAD_PRIORITY_MAX; 30} 31 32// https://pubs.opengroup.org/onlinepubs/9699919799/functions/sched_setparam.html 33int sched_setparam(pid_t pid, const struct sched_param* param) 34{ 35 Syscall::SC_scheduler_parameters_params parameters { 36 .pid_or_tid = pid, 37 .mode = Syscall::SchedulerParametersMode::Process, 38 .parameters = *param, 39 }; 40 int rc = syscall(SC_scheduler_set_parameters, &parameters); 41 __RETURN_WITH_ERRNO(rc, rc, -1); 42} 43 44// https://pubs.opengroup.org/onlinepubs/9699919799/functions/sched_getparam.html 45int sched_getparam(pid_t pid, struct sched_param* param) 46{ 47 Syscall::SC_scheduler_parameters_params parameters { 48 .pid_or_tid = pid, 49 .mode = Syscall::SchedulerParametersMode::Process, 50 .parameters = {}, 51 }; 52 int rc = syscall(SC_scheduler_get_parameters, &parameters); 53 if (rc == 0) 54 *param = parameters.parameters; 55 __RETURN_WITH_ERRNO(rc, rc, -1); 56} 57}