1 /* Definitions of constants and data structure for POSIX 1003.1b-1993
3 Copyright (C) 1996-1999,2001-2003,2005,2006,2007,2008,2009,2011,2012
4 Free Software Foundation, Inc.
5 This file is part of the GNU C Library.
7 The GNU C Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 The GNU C Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with the GNU C Library; if not, see
19 <http://www.gnu.org/licenses/>. */
21 #ifndef __need_schedparam
24 # error "Never include <bits/sched.h> directly; use <sched.h> instead."
28 /* Scheduling algorithms. */
33 /* Data structure to describe a process' schedulability. */
39 #endif /* need schedparam */
41 #if !defined __defined_schedparam \
42 && (defined __need_schedparam || defined _SCHED_H)
43 # define __defined_schedparam 1
44 /* Data structure to describe a process' schedulability. */
49 # undef __need_schedparam
53 #if defined _SCHED_H && !defined __cpu_set_t_defined
54 # define __cpu_set_t_defined
55 /* Size definition for CPU sets. */
56 # define __CPU_SETSIZE 1024
57 # define __NCPUBITS (8 * sizeof (__cpu_mask))
59 /* Type for array elements in 'cpu_set_t'. */
60 typedef unsigned long int __cpu_mask
;
62 /* Basic access functions. */
63 # define __CPUELT(cpu) ((cpu) / __NCPUBITS)
64 # define __CPUMASK(cpu) ((__cpu_mask) 1 << ((cpu) % __NCPUBITS))
66 /* Data structure to describe CPU mask. */
69 __cpu_mask __bits
[__CPU_SETSIZE
/ __NCPUBITS
];
72 /* Access functions for CPU masks. */
73 # if __GNUC_PREREQ (2, 91)
74 # define __CPU_ZERO_S(setsize, cpusetp) \
75 do __builtin_memset (cpusetp, '\0', setsize); while (0)
77 # define __CPU_ZERO_S(setsize, cpusetp) \
80 size_t __imax = (setsize) / sizeof (__cpu_mask); \
81 __cpu_mask *__bits = (cpusetp)->__bits; \
82 for (__i = 0; __i < __imax; ++__i) \
86 # define __CPU_SET_S(cpu, setsize, cpusetp) \
88 ({ size_t __cpu = (cpu); \
89 __cpu < 8 * (setsize) \
90 ? (((__cpu_mask *) ((cpusetp)->__bits))[__CPUELT (__cpu)] \
91 |= __CPUMASK (__cpu)) \
93 # define __CPU_CLR_S(cpu, setsize, cpusetp) \
95 ({ size_t __cpu = (cpu); \
96 __cpu < 8 * (setsize) \
97 ? (((__cpu_mask *) ((cpusetp)->__bits))[__CPUELT (__cpu)] \
98 &= ~__CPUMASK (__cpu)) \
100 # define __CPU_ISSET_S(cpu, setsize, cpusetp) \
102 ({ size_t __cpu = (cpu); \
103 __cpu < 8 * (setsize) \
104 ? ((((const __cpu_mask *) ((cpusetp)->__bits))[__CPUELT (__cpu)] \
105 & __CPUMASK (__cpu))) != 0 \
108 # define __CPU_COUNT_S(setsize, cpusetp) \
109 __sched_cpucount (setsize, cpusetp)
111 # if __GNUC_PREREQ (2, 91)
112 # define __CPU_EQUAL_S(setsize, cpusetp1, cpusetp2) \
113 (__builtin_memcmp (cpusetp1, cpusetp2, setsize) == 0)
115 # define __CPU_EQUAL_S(setsize, cpusetp1, cpusetp2) \
117 ({ const __cpu_mask *__arr1 = (cpusetp1)->__bits; \
118 const __cpu_mask *__arr2 = (cpusetp2)->__bits; \
119 size_t __imax = (setsize) / sizeof (__cpu_mask); \
121 for (__i = 0; __i < __imax; ++__i) \
122 if (__arr1[__i] != __arr2[__i]) \
127 # define __CPU_OP_S(setsize, destset, srcset1, srcset2, op) \
129 ({ cpu_set_t *__dest = (destset); \
130 const __cpu_mask *__arr1 = (srcset1)->__bits; \
131 const __cpu_mask *__arr2 = (srcset2)->__bits; \
132 size_t __imax = (setsize) / sizeof (__cpu_mask); \
134 for (__i = 0; __i < __imax; ++__i) \
135 ((__cpu_mask *) __dest->__bits)[__i] = __arr1[__i] op __arr2[__i]; \
138 # define __CPU_ALLOC_SIZE(count) \
139 ((((count) + __NCPUBITS - 1) / __NCPUBITS) * sizeof (__cpu_mask))
140 # define __CPU_ALLOC(count) __sched_cpualloc (count)
141 # define __CPU_FREE(cpuset) __sched_cpufree (cpuset)
145 extern int __sched_cpucount (size_t __setsize
, const cpu_set_t
*__setp
)
147 extern cpu_set_t
*__sched_cpualloc (size_t __count
) __THROW __wur
;
148 extern void __sched_cpufree (cpu_set_t
*__set
) __THROW
;