sched.odin 3.0 KB

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