Hurd: Fix mlock in all cases except non-readable pages.
[glibc.git] / bits / sched.h
blob348594bb0edf87d26d733a033ce5195a2d7493f3
1 /* Definitions of constants and data structure for POSIX 1003.1b-1993
2 scheduling interface.
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
23 #ifndef _SCHED_H
24 # error "Never include <bits/sched.h> directly; use <sched.h> instead."
25 #endif
28 /* Scheduling algorithms. */
29 #define SCHED_OTHER 0
30 #define SCHED_FIFO 1
31 #define SCHED_RR 2
33 /* Data structure to describe a process' schedulability. */
34 struct sched_param
36 int __sched_priority;
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. */
45 struct __sched_param
47 int __sched_priority;
49 # undef __need_schedparam
50 #endif
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. */
67 typedef struct
69 __cpu_mask __bits[__CPU_SETSIZE / __NCPUBITS];
70 } cpu_set_t;
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)
76 # else
77 # define __CPU_ZERO_S(setsize, cpusetp) \
78 do { \
79 size_t __i; \
80 size_t __imax = (setsize) / sizeof (__cpu_mask); \
81 __cpu_mask *__bits = (cpusetp)->__bits; \
82 for (__i = 0; __i < __imax; ++__i) \
83 __bits[__i] = 0; \
84 } while (0)
85 # endif
86 # define __CPU_SET_S(cpu, setsize, cpusetp) \
87 (__extension__ \
88 ({ size_t __cpu = (cpu); \
89 __cpu < 8 * (setsize) \
90 ? (((__cpu_mask *) ((cpusetp)->__bits))[__CPUELT (__cpu)] \
91 |= __CPUMASK (__cpu)) \
92 : 0; }))
93 # define __CPU_CLR_S(cpu, setsize, cpusetp) \
94 (__extension__ \
95 ({ size_t __cpu = (cpu); \
96 __cpu < 8 * (setsize) \
97 ? (((__cpu_mask *) ((cpusetp)->__bits))[__CPUELT (__cpu)] \
98 &= ~__CPUMASK (__cpu)) \
99 : 0; }))
100 # define __CPU_ISSET_S(cpu, setsize, cpusetp) \
101 (__extension__ \
102 ({ size_t __cpu = (cpu); \
103 __cpu < 8 * (setsize) \
104 ? ((((const __cpu_mask *) ((cpusetp)->__bits))[__CPUELT (__cpu)] \
105 & __CPUMASK (__cpu))) != 0 \
106 : 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)
114 # else
115 # define __CPU_EQUAL_S(setsize, cpusetp1, cpusetp2) \
116 (__extension__ \
117 ({ const __cpu_mask *__arr1 = (cpusetp1)->__bits; \
118 const __cpu_mask *__arr2 = (cpusetp2)->__bits; \
119 size_t __imax = (setsize) / sizeof (__cpu_mask); \
120 size_t __i; \
121 for (__i = 0; __i < __imax; ++__i) \
122 if (__arr1[__i] != __arr2[__i]) \
123 break; \
124 __i == __imax; }))
125 # endif
127 # define __CPU_OP_S(setsize, destset, srcset1, srcset2, op) \
128 (__extension__ \
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); \
133 size_t __i; \
134 for (__i = 0; __i < __imax; ++__i) \
135 ((__cpu_mask *) __dest->__bits)[__i] = __arr1[__i] op __arr2[__i]; \
136 __dest; }))
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)
143 __BEGIN_DECLS
145 extern int __sched_cpucount (size_t __setsize, const cpu_set_t *__setp)
146 __THROW;
147 extern cpu_set_t *__sched_cpualloc (size_t __count) __THROW __wur;
148 extern void __sched_cpufree (cpu_set_t *__set) __THROW;
150 __END_DECLS
152 #endif