sched.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <errno.h>
  7. #include <sched.h>
  8. #include <syscall.h>
  9. extern "C" {
  10. // https://pubs.opengroup.org/onlinepubs/9699919799/functions/sched_yield.html
  11. int sched_yield()
  12. {
  13. int rc = syscall(SC_yield);
  14. __RETURN_WITH_ERRNO(rc, rc, -1);
  15. }
  16. // https://pubs.opengroup.org/onlinepubs/9699919799/functions/sched_get_priority_min.html
  17. int sched_get_priority_min([[maybe_unused]] int policy)
  18. {
  19. return 0; // Idle
  20. }
  21. // https://pubs.opengroup.org/onlinepubs/9699919799/functions/sched_get_priority_max.html
  22. int sched_get_priority_max([[maybe_unused]] int policy)
  23. {
  24. return 3; // High
  25. }
  26. // https://pubs.opengroup.org/onlinepubs/9699919799/functions/sched_setparam.html
  27. int sched_setparam(pid_t pid, const struct sched_param* param)
  28. {
  29. int rc = syscall(SC_sched_setparam, pid, param);
  30. __RETURN_WITH_ERRNO(rc, rc, -1);
  31. }
  32. // https://pubs.opengroup.org/onlinepubs/9699919799/functions/sched_getparam.html
  33. int sched_getparam(pid_t pid, struct sched_param* param)
  34. {
  35. int rc = syscall(SC_sched_getparam, pid, param);
  36. __RETURN_WITH_ERRNO(rc, rc, -1);
  37. }
  38. }