Update copyright notices with scripts/update-copyrights
[glibc.git] / bits / sched.h
blobe79db042ee477632af5e2d2ced454b95be91c3f0
1 /* Definitions of constants and data structure for POSIX 1003.1b-1993
2 scheduling interface.
3 Copyright (C) 1996-2014 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
22 #ifndef _SCHED_H
23 # error "Never include <bits/sched.h> directly; use <sched.h> instead."
24 #endif
27 /* Scheduling algorithms. */
28 #define SCHED_OTHER 0
29 #define SCHED_FIFO 1
30 #define SCHED_RR 2
32 /* Data structure to describe a process' schedulability. */
33 struct sched_param
35 int __sched_priority;
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. */
44 struct __sched_param
46 int __sched_priority;
48 # undef __need_schedparam
49 #endif
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. */
66 typedef struct
68 __cpu_mask __bits[__CPU_SETSIZE / __NCPUBITS];
69 } cpu_set_t;
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)
75 # else
76 # define __CPU_ZERO_S(setsize, cpusetp) \
77 do { \
78 size_t __i; \
79 size_t __imax = (setsize) / sizeof (__cpu_mask); \
80 __cpu_mask *__bits = (cpusetp)->__bits; \
81 for (__i = 0; __i < __imax; ++__i) \
82 __bits[__i] = 0; \
83 } while (0)
84 # endif
85 # define __CPU_SET_S(cpu, setsize, cpusetp) \
86 (__extension__ \
87 ({ size_t __cpu = (cpu); \
88 __cpu < 8 * (setsize) \
89 ? (((__cpu_mask *) ((cpusetp)->__bits))[__CPUELT (__cpu)] \
90 |= __CPUMASK (__cpu)) \
91 : 0; }))
92 # define __CPU_CLR_S(cpu, setsize, cpusetp) \
93 (__extension__ \
94 ({ size_t __cpu = (cpu); \
95 __cpu < 8 * (setsize) \
96 ? (((__cpu_mask *) ((cpusetp)->__bits))[__CPUELT (__cpu)] \
97 &= ~__CPUMASK (__cpu)) \
98 : 0; }))
99 # define __CPU_ISSET_S(cpu, setsize, cpusetp) \
100 (__extension__ \
101 ({ size_t __cpu = (cpu); \
102 __cpu < 8 * (setsize) \
103 ? ((((const __cpu_mask *) ((cpusetp)->__bits))[__CPUELT (__cpu)] \
104 & __CPUMASK (__cpu))) != 0 \
105 : 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)
113 # else
114 # define __CPU_EQUAL_S(setsize, cpusetp1, cpusetp2) \
115 (__extension__ \
116 ({ const __cpu_mask *__arr1 = (cpusetp1)->__bits; \
117 const __cpu_mask *__arr2 = (cpusetp2)->__bits; \
118 size_t __imax = (setsize) / sizeof (__cpu_mask); \
119 size_t __i; \
120 for (__i = 0; __i < __imax; ++__i) \
121 if (__arr1[__i] != __arr2[__i]) \
122 break; \
123 __i == __imax; }))
124 # endif
126 # define __CPU_OP_S(setsize, destset, srcset1, srcset2, op) \
127 (__extension__ \
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); \
132 size_t __i; \
133 for (__i = 0; __i < __imax; ++__i) \
134 ((__cpu_mask *) __dest->__bits)[__i] = __arr1[__i] op __arr2[__i]; \
135 __dest; }))
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)
142 __BEGIN_DECLS
144 extern int __sched_cpucount (size_t __setsize, const cpu_set_t *__setp)
145 __THROW;
146 extern cpu_set_t *__sched_cpualloc (size_t __count) __THROW __wur;
147 extern void __sched_cpufree (cpu_set_t *__set) __THROW;
149 __END_DECLS
151 #endif