1 /**
2  * D header file for POSIX.
3  *
4  * Copyright: Copyright Sean Kelly 2005 - 2009.
5  * License:   $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0).
6  * Authors:   Sean Kelly,
7               Alex Rønne Petersen
8  * Standards: The Open Group Base Specifications Issue 6, IEEE Std 1003.1, 2004 Edition
9  */
10 
11 /*          Copyright Sean Kelly 2005 - 2009.
12  * Distributed under the Boost Software License, Version 1.0.
13  *    (See accompanying file LICENSE or copy at
14  *          http://www.boost.org/LICENSE_1_0.txt)
15  */
16 module core.sys.posix.sched;
17 
18 import core.sys.posix.config;
19 public import core.sys.posix.time;
20 public import core.sys.posix.sys.types;
21 
22 version (OSX)
23     version = Darwin;
24 else version (iOS)
25     version = Darwin;
26 else version (TVOS)
27     version = Darwin;
28 else version (WatchOS)
29     version = Darwin;
30 
31 version (Posix):
32 extern (C):
33 nothrow:
34 @nogc:
35 
36 //
37 // Required
38 //
39 /*
40 struct sched_param
41 {
42     int sched_priority (THR)
43     int sched_ss_low_priority (SS|TSP)
44     struct timespec sched_ss_repl_period (SS|TSP)
45     struct timespec sched_ss_init_budget (SS|TSP)
46     int sched_ss_max_repl (SS|TSP)
47 }
48 
49 SCHED_FIFO
50 SCHED_RR
51 SCHED_SPORADIC (SS|TSP)
52 SCHED_OTHER
53 
54 int sched_getparam(pid_t, sched_param*);
55 int sched_getscheduler(pid_t);
56 int sched_setparam(pid_t, const scope sched_param*);
57 int sched_setscheduler(pid_t, int, const scope sched_param*);
58 */
59 
60 version (linux)
61 {
62     version (CRuntime_Musl)
63     {
64         struct sched_param
65         {
66             int sched_priority;
67             int __reserved1;
68             static if (muslRedirTime64)
69                 c_long[2] __reserved2;
70             else
71                 timespec[2] __reserved2;
72             int __reserved3;
73         }
74     }
75     else
76     {
77         struct sched_param
78         {
79             int sched_priority;
80         }
81     }
82 
83     enum SCHED_OTHER    = 0;
84     enum SCHED_FIFO     = 1;
85     enum SCHED_RR       = 2;
86     //SCHED_SPORADIC (SS|TSP)
87     enum SCHED_BATCH    = 3;
88     enum SCHED_IDLE     = 5;
89     enum SCHED_RESET_ON_FORK = 0x40000000;
90 }
91 else version (Darwin)
92 {
93     enum SCHED_OTHER    = 1;
94     enum SCHED_FIFO     = 4;
95     enum SCHED_RR       = 2;
96     //SCHED_SPORADIC (SS|TSP)
97 
98     struct sched_param
99     {
100         int                             sched_priority;
101         byte[__PTHREAD_MUTEX_SIZE__]    __opaque;
102     }
103 }
104 else version (FreeBSD)
105 {
106     struct sched_param
107     {
108         int sched_priority;
109     }
110 
111     enum SCHED_FIFO     = 1;
112     enum SCHED_OTHER    = 2;
113     enum SCHED_RR       = 3;
114 }
115 else version (NetBSD)
116 {
117     struct sched_param
118     {
119         int sched_priority;
120     }
121 
122     enum SCHED_FIFO     = 1;
123     enum SCHED_OTHER    = 0;
124     enum SCHED_RR       = 2;
125 }
126 else version (OpenBSD)
127 {
128     struct sched_param
129     {
130         int sched_priority;
131     }
132 
133     enum SCHED_FIFO     = 1;
134     enum SCHED_OTHER    = 2;
135     enum SCHED_RR       = 3;
136 }
137 else version (DragonFlyBSD)
138 {
139     struct sched_param
140     {
141         int sched_priority;
142     }
143 
144     enum SCHED_FIFO     = 1;
145     enum SCHED_OTHER    = 2;
146     enum SCHED_RR       = 3;
147 }
148 else version (Solaris)
149 {
150     struct sched_param
151     {
152         int sched_priority;
153         int[8] sched_pad;
154     }
155 
156     enum SCHED_OTHER = 0;
157     enum SCHED_FIFO = 1;
158     enum SCHED_RR = 2;
159     enum SCHED_SYS = 3;
160     enum SCHED_IA = 4;
161     enum SCHED_FSS = 5;
162     enum SCHED_FX = 6;
163     enum _SCHED_NEXT = 7;
164 }
165 else
166 {
167     static assert(false, "Unsupported platform");
168 }
169 
170 int sched_getparam(pid_t, sched_param*);
171 int sched_getscheduler(pid_t);
172 int sched_setparam(pid_t, const scope sched_param*);
173 int sched_setscheduler(pid_t, int, const scope sched_param*);
174 
175 //
176 // Thread (THR)
177 //
178 /*
179 int sched_yield();
180 */
181 
182 version (CRuntime_Glibc)
183 {
184     int sched_yield();
185 }
186 else version (Darwin)
187 {
188     int sched_yield();
189 }
190 else version (FreeBSD)
191 {
192     int sched_yield();
193 }
194 else version (NetBSD)
195 {
196     int sched_yield();
197 }
198 else version (OpenBSD)
199 {
200     int sched_yield();
201 }
202 else version (DragonFlyBSD)
203 {
204     int sched_yield();
205 }
206 else version (Solaris)
207 {
208     int sched_yield();
209 }
210 else version (CRuntime_Bionic)
211 {
212     int sched_yield();
213 }
214 else version (CRuntime_Musl)
215 {
216     int sched_yield();
217 }
218 else version (CRuntime_UClibc)
219 {
220     int sched_yield();
221 }
222 else
223 {
224     static assert(false, "Unsupported platform");
225 }
226 
227 //
228 // Scheduling (TPS)
229 //
230 /*
231 int sched_get_priority_max(int);
232 int sched_get_priority_min(int);
233 int sched_rr_get_interval(pid_t, timespec*);
234 */
235 
236 version (CRuntime_Glibc)
237 {
238     int sched_get_priority_max(int);
239     int sched_get_priority_min(int);
240     int sched_rr_get_interval(pid_t, timespec*);
241 }
242 else version (Darwin)
243 {
244     int sched_get_priority_min(int);
245     int sched_get_priority_max(int);
246     //int sched_rr_get_interval(pid_t, timespec*); // FIXME: unavailable?
247 }
248 else version (FreeBSD)
249 {
250     int sched_get_priority_min(int);
251     int sched_get_priority_max(int);
252     int sched_rr_get_interval(pid_t, timespec*);
253 }
254 else version (NetBSD)
255 {
256     int sched_get_priority_min(int);
257     int sched_get_priority_max(int);
258     int sched_rr_get_interval(pid_t, timespec*);
259 }
260 else version (OpenBSD)
261 {
262     int sched_get_priority_min(int);
263     int sched_get_priority_max(int);
264     int sched_rr_get_interval(pid_t, timespec*);
265 }
266 else version (DragonFlyBSD)
267 {
268     int sched_get_priority_min(int);
269     int sched_get_priority_max(int);
270     int sched_rr_get_interval(pid_t, timespec*);
271 }
272 else version (Solaris)
273 {
274     int sched_get_priority_max(int);
275     int sched_get_priority_min(int);
276     int sched_rr_get_interval(pid_t, timespec*);
277 }
278 else version (CRuntime_Bionic)
279 {
280     int sched_get_priority_max(int);
281     int sched_get_priority_min(int);
282     int sched_rr_get_interval(pid_t, timespec*);
283 }
284 else version (CRuntime_Musl)
285 {
286     int sched_get_priority_max(int);
287     int sched_get_priority_min(int);
288     pragma(mangle, muslRedirTime64Mangle!("sched_rr_get_interval", "__sched_rr_get_interval_time64"))
289     int sched_rr_get_interval(pid_t, timespec*);
290 }
291 else version (CRuntime_UClibc)
292 {
293     int sched_get_priority_max(int);
294     int sched_get_priority_min(int);
295     int sched_rr_get_interval(pid_t, timespec*);
296 }
297 else
298 {
299     static assert(false, "Unsupported platform");
300 }