1 /* Definitions of constants and data structure for POSIX 1003.1b-1993
3 Copyright (C) 1996-2016 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
20 #ifndef __need_schedparam
23 # error "Never include <bits/sched.h> directly; use <sched.h> instead."
27 /* Scheduling algorithms. */
32 /* Data structure to describe a process' schedulability. */
38 #endif /* need schedparam */
40 #if !defined __defined_schedparam \
41 && (defined __need_schedparam || defined _SCHED_H)
42 # define __defined_schedparam 1
43 /* Data structure to describe a process' schedulability. */
48 # undef __need_schedparam
52 #if defined _SCHED_H && !defined __cpu_set_t_defined
53 # define __cpu_set_t_defined
54 /* Size definition for CPU sets. */
55 # define __CPU_SETSIZE 1024
56 # define __NCPUBITS (8 * sizeof (__cpu_mask))
58 /* Type for array elements in 'cpu_set_t'. */
59 typedef unsigned long int __cpu_mask
;
61 /* Basic access functions. */
62 # define __CPUELT(cpu) ((cpu) / __NCPUBITS)
63 # define __CPUMASK(cpu) ((__cpu_mask) 1 << ((cpu) % __NCPUBITS))
65 /* Data structure to describe CPU mask. */
68 __cpu_mask __bits
[__CPU_SETSIZE
/ __NCPUBITS
];
71 /* Access functions for CPU masks. */
72 # if __GNUC_PREREQ (2, 91)
73 # define __CPU_ZERO_S(setsize, cpusetp) \
74 do __builtin_memset (cpusetp, '\0', setsize); while (0)
76 # define __CPU_ZERO_S(setsize, cpusetp) \
79 size_t __imax = (setsize) / sizeof (__cpu_mask); \
80 __cpu_mask *__bits = (cpusetp)->__bits; \
81 for (__i = 0; __i < __imax; ++__i) \
85 # define __CPU_SET_S(cpu, setsize, cpusetp) \
87 ({ size_t __cpu = (cpu); \
88 __cpu < 8 * (setsize) \
89 ? (((__cpu_mask *) ((cpusetp)->__bits))[__CPUELT (__cpu)] \
90 |= __CPUMASK (__cpu)) \
92 # define __CPU_CLR_S(cpu, setsize, cpusetp) \
94 ({ size_t __cpu = (cpu); \
95 __cpu < 8 * (setsize) \
96 ? (((__cpu_mask *) ((cpusetp)->__bits))[__CPUELT (__cpu)] \
97 &= ~__CPUMASK (__cpu)) \
99 # define __CPU_ISSET_S(cpu, setsize, cpusetp) \
101 ({ size_t __cpu = (cpu); \
102 __cpu < 8 * (setsize) \
103 ? ((((const __cpu_mask *) ((cpusetp)->__bits))[__CPUELT (__cpu)] \
104 & __CPUMASK (__cpu))) != 0 \
107 # define __CPU_COUNT_S(setsize, cpusetp) \
108 __sched_cpucount (setsize, cpusetp)
110 # if __GNUC_PREREQ (2, 91)
111 # define __CPU_EQUAL_S(setsize, cpusetp1, cpusetp2) \
112 (__builtin_memcmp (cpusetp1, cpusetp2, setsize) == 0)
114 # define __CPU_EQUAL_S(setsize, cpusetp1, cpusetp2) \
116 ({ const __cpu_mask *__arr1 = (cpusetp1)->__bits; \
117 const __cpu_mask *__arr2 = (cpusetp2)->__bits; \
118 size_t __imax = (setsize) / sizeof (__cpu_mask); \
120 for (__i = 0; __i < __imax; ++__i) \
121 if (__arr1[__i] != __arr2[__i]) \
126 # define __CPU_OP_S(setsize, destset, srcset1, srcset2, op) \
128 ({ cpu_set_t *__dest = (destset); \
129 const __cpu_mask *__arr1 = (srcset1)->__bits; \
130 const __cpu_mask *__arr2 = (srcset2)->__bits; \
131 size_t __imax = (setsize) / sizeof (__cpu_mask); \
133 for (__i = 0; __i < __imax; ++__i) \
134 ((__cpu_mask *) __dest->__bits)[__i] = __arr1[__i] op __arr2[__i]; \
137 # define __CPU_ALLOC_SIZE(count) \
138 ((((count) + __NCPUBITS - 1) / __NCPUBITS) * sizeof (__cpu_mask))
139 # define __CPU_ALLOC(count) __sched_cpualloc (count)
140 # define __CPU_FREE(cpuset) __sched_cpufree (cpuset)
144 extern int __sched_cpucount (size_t __setsize
, const cpu_set_t
*__setp
)
146 extern cpu_set_t
*__sched_cpualloc (size_t __count
) __THROW __wur
;
147 extern void __sched_cpufree (cpu_set_t
*__set
) __THROW
;