sched.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 THREAD_PRIORITY_MIN;
  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 THREAD_PRIORITY_MAX;
  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. Syscall::SC_scheduler_parameters_params parameters {
  30. .pid_or_tid = pid,
  31. .mode = Syscall::SchedulerParametersMode::Process,
  32. .parameters = *param,
  33. };
  34. int rc = syscall(SC_scheduler_set_parameters, &parameters);
  35. __RETURN_WITH_ERRNO(rc, rc, -1);
  36. }
  37. // https://pubs.opengroup.org/onlinepubs/9699919799/functions/sched_getparam.html
  38. int sched_getparam(pid_t pid, struct sched_param* param)
  39. {
  40. Syscall::SC_scheduler_parameters_params parameters {
  41. .pid_or_tid = pid,
  42. .mode = Syscall::SchedulerParametersMode::Process,
  43. .parameters = {},
  44. };
  45. int rc = syscall(SC_scheduler_get_parameters, &parameters);
  46. if (rc == 0)
  47. *param = parameters.parameters;
  48. __RETURN_WITH_ERRNO(rc, rc, -1);
  49. }
  50. }