xref: /haiku/headers/compatibility/gnu/sched.h (revision fc7456e9b1ec38c941134ed6d01c438cf289381e)
1 /*
2 * Copyright 2023 Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
4 */
5 #ifndef _GNU_SCHED_H_
6 #define _GNU_SCHED_H_
7 
8 
9 #include_next <sched.h>
10 #include <features.h>
11 
12 #include <stdint.h>
13 #include <sys/types.h>
14 
15 
16 #ifdef _DEFAULT_SOURCE
17 
18 
19 #ifndef CPU_SETSIZE
20 #define CPU_SETSIZE 1024
21 #endif
22 
23 
24 typedef __haiku_uint32 cpuset_mask;
25 
26 #ifndef _howmany
27 #define _howmany(x, y) (((x) + ((y) - 1)) / (y))
28 #endif
29 
30 #define NCPUSETBITS (sizeof(cpuset_mask) * 8) /* bits per mask */
31 
32 typedef struct _cpuset {
33 	cpuset_mask bits[_howmany(CPU_SETSIZE, NCPUSETBITS)];
34 } cpuset_t;
35 
36 
37 #define _CPUSET_BITSINDEX(cpu) ((cpu) / NCPUSETBITS)
38 #define _CPUSET_BIT(cpu) (1L << ((cpu) % NCPUSETBITS))
39 
40 /* FD_ZERO uses memset */
41 #include <string.h>
42 
43 #define CPUSET_ZERO(set) memset((set), 0, sizeof(cpuset_t))
44 #define CPUSET_SET(cpu, set) ((set)->bits[_CPUSET_BITSINDEX(cpu)] |= _CPUSET_BIT(cpu))
45 #define CPUSET_CLR(cpu, set) ((set)->bits[_CPUSET_BITSINDEX(cpu)] &= ~_CPUSET_BIT(cpu))
46 #define CPUSET_ISSET(cpu, set) ((set)->bits[_CPUSET_BITSINDEX(cpu)] & _CPUSET_BIT(cpu))
47 #define CPUSET_COPY(source, target) (*(target) = *(source))
48 
49 
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53 
54 extern int sched_getcpu(void);
55 extern int sched_setaffinity(pid_t id, size_t cpusetsize, const cpuset_t* mask);
56 extern int sched_getaffinity(pid_t id, size_t cpusetsize, cpuset_t* mask);
57 
58 #ifdef __cplusplus
59 }
60 #endif
61 
62 
63 #endif
64 
65 
66 #endif  /* _GNU_SCHED_H_ */
67