1 /* Definitions of constants and data structure for POSIX 1003.1b-1993
3 Copyright (C) 1996-1999,2001-2003,2005,2006,2007,2008,2009
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, write to the Free
19 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
22 #ifndef __need_schedparam
25 # error "Never include <bits/sched.h> directly; use <sched.h> instead."
29 /* Scheduling algorithms. */
34 /* Data structure to describe a process' schedulability. */
40 #endif /* need schedparam */
42 #if !defined __defined_schedparam \
43 && (defined __need_schedparam || defined _SCHED_H)
44 # define __defined_schedparam 1
45 /* Data structure to describe a process' schedulability. */
50 # undef __need_schedparam
54 #if defined _SCHED_H && !defined __cpu_set_t_defined
55 # define __cpu_set_t_defined
56 /* Size definition for CPU sets. */
57 # define __CPU_SETSIZE 1024
58 # define __NCPUBITS (8 * sizeof (__cpu_mask))
60 /* Type for array elements in 'cpu_set_t'. */
61 typedef unsigned long int __cpu_mask;
63 /* Basic access functions. */
64 # define __CPUELT(cpu) ((cpu) / __NCPUBITS)
65 # define __CPUMASK(cpu) ((__cpu_mask) 1 << ((cpu) % __NCPUBITS))
67 /* Data structure to describe CPU mask. */
70 __cpu_mask __bits[__CPU_SETSIZE / __NCPUBITS];
73 /* Access functions for CPU masks. */
74 # if __GNUC_PREREQ (2, 91)
75 # define __CPU_ZERO_S(setsize, cpusetp) \
76 do __builtin_memset (cpusetp, '\0', setsize); while (0)
78 # define __CPU_ZERO_S(setsize, cpusetp) \
81 size_t __imax = (setsize) / sizeof (__cpu_mask); \
82 __cpu_mask *__bits = (cpusetp)->__bits; \
83 for (__i = 0; __i < __imax; ++__i) \
87 # define __CPU_SET_S(cpu, setsize, cpusetp) \
89 ({ size_t __cpu = (cpu); \
90 __cpu < 8 * (setsize) \
91 ? (((__cpu_mask *) ((cpusetp)->__bits))[__CPUELT (__cpu)] \
92 |= __CPUMASK (__cpu)) \
94 # define __CPU_CLR_S(cpu, setsize, cpusetp) \
96 ({ size_t __cpu = (cpu); \
97 __cpu < 8 * (setsize) \
98 ? (((__cpu_mask *) ((cpusetp)->__bits))[__CPUELT (__cpu)] \
99 &= ~__CPUMASK (__cpu)) \
101 # define __CPU_ISSET_S(cpu, setsize, cpusetp) \
103 ({ size_t __cpu = (cpu); \
104 __cpu < 8 * (setsize) \
105 ? ((((__const __cpu_mask *) ((cpusetp)->__bits))[__CPUELT (__cpu)] \
106 & __CPUMASK (__cpu))) != 0 \
109 # define __CPU_COUNT_S(setsize, cpusetp) \
110 __sched_cpucount (setsize, cpusetp)
112 # if __GNUC_PREREQ (2, 91)
113 # define __CPU_EQUAL_S(setsize, cpusetp1, cpusetp2) \
114 (__builtin_memcmp (cpusetp1, cpusetp2, setsize) == 0)
116 # define __CPU_EQUAL_S(setsize, cpusetp1, cpusetp2) \
118 ({ __const __cpu_mask *__arr1 = (cpusetp1)->__bits; \
119 __const __cpu_mask *__arr2 = (cpusetp2)->__bits; \
120 size_t __imax = (setsize) / sizeof (__cpu_mask); \
122 for (__i = 0; __i < __imax; ++__i) \
123 if (__bits[__i] != __bits[__i]) \
128 # define __CPU_OP_S(setsize, destset, srcset1, srcset2, op) \
130 ({ cpu_set_t *__dest = (destset); \
131 __const __cpu_mask *__arr1 = (srcset1)->__bits; \
132 __const __cpu_mask *__arr2 = (srcset2)->__bits; \
133 size_t __imax = (setsize) / sizeof (__cpu_mask); \
135 for (__i = 0; __i < __imax; ++__i) \
136 ((__cpu_mask *) __dest->__bits)[__i] = __arr1[__i] op __arr2[__i]; \
139 # define __CPU_ALLOC_SIZE(count) \
140 ((((count) + __NCPUBITS - 1) / __NCPUBITS) * sizeof (__cpu_mask))
141 # define __CPU_ALLOC(count) __sched_cpualloc (count)
142 # define __CPU_FREE(cpuset) __sched_cpufree (cpuset)
146 extern int __sched_cpucount (size_t __setsize, const cpu_set_t *__setp)
148 extern cpu_set_t *__sched_cpualloc (size_t __count) __THROW __wur;
149 extern void __sched_cpufree (cpu_set_t *__set) __THROW;