Don't always provide definition of gets checking version
[platform/upstream/glibc.git] / bits / sched.h
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.
6
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.
11
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.
16
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
20    02111-1307 USA.  */
21
22 #ifndef __need_schedparam
23
24 #ifndef _SCHED_H
25 # error "Never include <bits/sched.h> directly; use <sched.h> instead."
26 #endif
27
28
29 /* Scheduling algorithms.  */
30 #define SCHED_OTHER     0
31 #define SCHED_FIFO      1
32 #define SCHED_RR        2
33
34 /* Data structure to describe a process' schedulability.  */
35 struct sched_param
36 {
37   int __sched_priority;
38 };
39
40 #endif  /* need schedparam */
41
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.  */
46 struct __sched_param
47   {
48     int __sched_priority;
49   };
50 # undef __need_schedparam
51 #endif
52
53
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))
59
60 /* Type for array elements in 'cpu_set_t'.  */
61 typedef unsigned long int __cpu_mask;
62
63 /* Basic access functions.  */
64 # define __CPUELT(cpu)  ((cpu) / __NCPUBITS)
65 # define __CPUMASK(cpu) ((__cpu_mask) 1 << ((cpu) % __NCPUBITS))
66
67 /* Data structure to describe CPU mask.  */
68 typedef struct
69 {
70   __cpu_mask __bits[__CPU_SETSIZE / __NCPUBITS];
71 } cpu_set_t;
72
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)
77 # else
78 #  define __CPU_ZERO_S(setsize, cpusetp) \
79   do {                                                                        \
80     size_t __i;                                                               \
81     size_t __imax = (setsize) / sizeof (__cpu_mask);                          \
82     __cpu_mask *__bits = (cpusetp)->__bits;                                   \
83     for (__i = 0; __i < __imax; ++__i)                                        \
84       __bits[__i] = 0;                                                        \
85   } while (0)
86 # endif
87 # define __CPU_SET_S(cpu, setsize, cpusetp) \
88   (__extension__                                                              \
89    ({ size_t __cpu = (cpu);                                                   \
90       __cpu < 8 * (setsize)                                                   \
91       ? (((__cpu_mask *) ((cpusetp)->__bits))[__CPUELT (__cpu)]               \
92          |= __CPUMASK (__cpu))                                                \
93       : 0; }))
94 # define __CPU_CLR_S(cpu, setsize, cpusetp) \
95   (__extension__                                                              \
96    ({ size_t __cpu = (cpu);                                                   \
97       __cpu < 8 * (setsize)                                                   \
98       ? (((__cpu_mask *) ((cpusetp)->__bits))[__CPUELT (__cpu)]               \
99          &= ~__CPUMASK (__cpu))                                               \
100       : 0; }))
101 # define __CPU_ISSET_S(cpu, setsize, cpusetp) \
102   (__extension__                                                              \
103    ({ size_t __cpu = (cpu);                                                   \
104       __cpu < 8 * (setsize)                                                   \
105       ? ((((const __cpu_mask *) ((cpusetp)->__bits))[__CPUELT (__cpu)]      \
106           & __CPUMASK (__cpu))) != 0                                          \
107       : 0; }))
108
109 # define __CPU_COUNT_S(setsize, cpusetp) \
110   __sched_cpucount (setsize, cpusetp)
111
112 # if __GNUC_PREREQ (2, 91)
113 #  define __CPU_EQUAL_S(setsize, cpusetp1, cpusetp2) \
114   (__builtin_memcmp (cpusetp1, cpusetp2, setsize) == 0)
115 # else
116 #  define __CPU_EQUAL_S(setsize, cpusetp1, cpusetp2) \
117   (__extension__                                                              \
118    ({ const __cpu_mask *__arr1 = (cpusetp1)->__bits;                          \
119       const __cpu_mask *__arr2 = (cpusetp2)->__bits;                          \
120       size_t __imax = (setsize) / sizeof (__cpu_mask);                        \
121       size_t __i;                                                             \
122       for (__i = 0; __i < __imax; ++__i)                                      \
123         if (__arr1[__i] != __arr2[__i])                                       \
124           break;                                                              \
125       __i == __imax; }))
126 # endif
127
128 # define __CPU_OP_S(setsize, destset, srcset1, srcset2, op) \
129   (__extension__                                                              \
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);                        \
134       size_t __i;                                                             \
135       for (__i = 0; __i < __imax; ++__i)                                      \
136         ((__cpu_mask *) __dest->__bits)[__i] = __arr1[__i] op __arr2[__i];    \
137       __dest; }))
138
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)
143
144 __BEGIN_DECLS
145
146 extern int __sched_cpucount (size_t __setsize, const cpu_set_t *__setp)
147      __THROW;
148 extern cpu_set_t *__sched_cpualloc (size_t __count) __THROW __wur;
149 extern void __sched_cpufree (cpu_set_t *__set) __THROW;
150
151 __END_DECLS
152
153 #endif