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