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