sched.odin 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #+build linux, darwin, netbsd, openbsd, freebsd
  2. package posix
  3. import "core:c"
  4. when ODIN_OS == .Darwin {
  5. foreign import lib "system:System.framework"
  6. } else {
  7. foreign import lib "system:c"
  8. }
  9. // sched.h - execution scheduling
  10. foreign lib {
  11. /*
  12. Returns the minimum for the given scheduling policy.
  13. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/sched_get_priority_max.html ]]
  14. */
  15. sched_get_priority_max :: proc(policy: Sched_Policy) -> c.int ---
  16. /*
  17. Returns the maximum for the given scheduling policy.
  18. Returns: -1 (setting errno) on failure, the maximum on success
  19. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/sched_get_priority_max.html ]]
  20. */
  21. sched_get_priority_min :: proc(policy: Sched_Policy) -> c.int ---
  22. /*
  23. Forces the running thread to relinquish the processor until it again becomes the head of its thread list.
  24. */
  25. sched_yield :: proc() -> result ---
  26. /* NOTE: unimplemented on darwin (I think?).
  27. /*
  28. Get the scheduling params of a process, pid of 0 will return that of the current process.
  29. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/sched_getparam.html ]]
  30. */
  31. sched_getparam :: proc(pid: pid_t, param: ^sched_param) -> result ---
  32. /*
  33. Sets the scheduling parameters of the given process, pid of 0 will set that of the current process.
  34. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/sched_setparam.html ]]
  35. */
  36. sched_setparam :: proc(pid: pid_t, param: ^sched_param) -> result ---
  37. /*
  38. Returns the scheduling policy of a process, pid of 0 will return that of the current process.
  39. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/sched_getscheduler.html ]]
  40. */
  41. sched_getscheduler :: proc(pid: pid_t) -> Sched_Policy ---
  42. /*
  43. Sets the scheduling policy and parameters of the process, pid 0 will be the current process.
  44. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/sched_setscheduler.html ]]
  45. */
  46. sched_setscheduler :: proc(pid: pid_t, policy: Sched_Policy, param: ^sched_param) -> result ---
  47. /*
  48. Updates the timespec structure to contain the current execution time limit for the process.
  49. pid of 0 will return that of the current process.
  50. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/sched_rr_get_interval.html ]]
  51. */
  52. sched_rr_get_interval :: proc(pid: pid_t, interval: ^timespec) -> result ---
  53. */
  54. }
  55. Sched_Policy :: enum c.int {
  56. // Error condition of sched_getscheduler.
  57. ERROR = -1,
  58. // First in-first out (FIFO) scheduling policy.
  59. FIFO = SCHED_FIFO,
  60. // Round robin scheduling policy.
  61. RR = SCHED_RR,
  62. // Another scheduling policy.
  63. OTHER = SCHED_OTHER,
  64. }
  65. when ODIN_OS == .Darwin {
  66. SCHED_FIFO :: 4
  67. SCHED_RR :: 2
  68. // SCHED_SPORADIC :: 3 NOTE: not a thing on freebsd, netbsd and probably others, leaving it out
  69. SCHED_OTHER :: 1
  70. } else when ODIN_OS == .FreeBSD || ODIN_OS == .OpenBSD {
  71. SCHED_FIFO :: 1
  72. SCHED_RR :: 3
  73. SCHED_OTHER :: 2
  74. } else when ODIN_OS == .NetBSD || ODIN_OS == .Linux {
  75. SCHED_OTHER :: 0
  76. SCHED_FIFO :: 1
  77. SCHED_RR :: 2
  78. }