modernc.org/cc@v1.0.1/v2/headers/linux_386/usr/include/i386-linux-gnu/bits/cpu-set.h (about)

     1  /* Definition of the cpu_set_t structure used by the POSIX 1003.1b-1993
     2     scheduling interface.
     3     Copyright (C) 1996-2018 Free Software Foundation, Inc.
     4     This file is part of the GNU C Library.
     5  
     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.
    10  
    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.
    15  
    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/>.  */
    19  
    20  #ifndef _BITS_CPU_SET_H
    21  #define _BITS_CPU_SET_H 1
    22  
    23  #ifndef _SCHED_H
    24  # error "Never include <bits/cpu-set.h> directly; use <sched.h> instead."
    25  #endif
    26  
    27  /* Size definition for CPU sets.  */
    28  #define __CPU_SETSIZE	1024
    29  #define __NCPUBITS	(8 * sizeof (__cpu_mask))
    30  
    31  /* Type for array elements in 'cpu_set_t'.  */
    32  typedef __CPU_MASK_TYPE __cpu_mask;
    33  
    34  /* Basic access functions.  */
    35  #define __CPUELT(cpu)	((cpu) / __NCPUBITS)
    36  #define __CPUMASK(cpu)	((__cpu_mask) 1 << ((cpu) % __NCPUBITS))
    37  
    38  /* Data structure to describe CPU mask.  */
    39  typedef struct {
    40  	__cpu_mask __bits[__CPU_SETSIZE / __NCPUBITS];
    41  } cpu_set_t;
    42  
    43  /* Access functions for CPU masks.  */
    44  #if __GNUC_PREREQ (2, 91)
    45  # define __CPU_ZERO_S(setsize, cpusetp) \
    46    do __builtin_memset (cpusetp, '\0', setsize); while (0)
    47  #else
    48  # define __CPU_ZERO_S(setsize, cpusetp) \
    49    do {									      \
    50      size_t __i;								      \
    51      size_t __imax = (setsize) / sizeof (__cpu_mask);			      \
    52      __cpu_mask *__bits = (cpusetp)->__bits;				      \
    53      for (__i = 0; __i < __imax; ++__i)					      \
    54        __bits[__i] = 0;							      \
    55    } while (0)
    56  #endif
    57  #define __CPU_SET_S(cpu, setsize, cpusetp) \
    58    (__extension__							      \
    59     ({ size_t __cpu = (cpu);						      \
    60        __cpu / 8 < (setsize)						      \
    61        ? (((__cpu_mask *) ((cpusetp)->__bits))[__CPUELT (__cpu)]		      \
    62  	 |= __CPUMASK (__cpu))						      \
    63        : 0; }))
    64  #define __CPU_CLR_S(cpu, setsize, cpusetp) \
    65    (__extension__							      \
    66     ({ size_t __cpu = (cpu);						      \
    67        __cpu / 8 < (setsize)						      \
    68        ? (((__cpu_mask *) ((cpusetp)->__bits))[__CPUELT (__cpu)]		      \
    69  	 &= ~__CPUMASK (__cpu))						      \
    70        : 0; }))
    71  #define __CPU_ISSET_S(cpu, setsize, cpusetp) \
    72    (__extension__							      \
    73     ({ size_t __cpu = (cpu);						      \
    74        __cpu / 8 < (setsize)						      \
    75        ? ((((const __cpu_mask *) ((cpusetp)->__bits))[__CPUELT (__cpu)]	      \
    76  	  & __CPUMASK (__cpu))) != 0					      \
    77        : 0; }))
    78  
    79  #define __CPU_COUNT_S(setsize, cpusetp) \
    80    __sched_cpucount (setsize, cpusetp)
    81  
    82  #if __GNUC_PREREQ (2, 91)
    83  # define __CPU_EQUAL_S(setsize, cpusetp1, cpusetp2) \
    84    (__builtin_memcmp (cpusetp1, cpusetp2, setsize) == 0)
    85  #else
    86  # define __CPU_EQUAL_S(setsize, cpusetp1, cpusetp2) \
    87    (__extension__							      \
    88     ({ const __cpu_mask *__arr1 = (cpusetp1)->__bits;			      \
    89        const __cpu_mask *__arr2 = (cpusetp2)->__bits;			      \
    90        size_t __imax = (setsize) / sizeof (__cpu_mask);			      \
    91        size_t __i;							      \
    92        for (__i = 0; __i < __imax; ++__i)				      \
    93  	if (__arr1[__i] != __arr2[__i])					      \
    94  	  break;							      \
    95        __i == __imax; }))
    96  #endif
    97  
    98  #define __CPU_OP_S(setsize, destset, srcset1, srcset2, op) \
    99    (__extension__							      \
   100     ({ cpu_set_t *__dest = (destset);					      \
   101        const __cpu_mask *__arr1 = (srcset1)->__bits;			      \
   102        const __cpu_mask *__arr2 = (srcset2)->__bits;			      \
   103        size_t __imax = (setsize) / sizeof (__cpu_mask);			      \
   104        size_t __i;							      \
   105        for (__i = 0; __i < __imax; ++__i)				      \
   106  	((__cpu_mask *) __dest->__bits)[__i] = __arr1[__i] op __arr2[__i];    \
   107        __dest; }))
   108  
   109  #define __CPU_ALLOC_SIZE(count) \
   110    ((((count) + __NCPUBITS - 1) / __NCPUBITS) * sizeof (__cpu_mask))
   111  #define __CPU_ALLOC(count) __sched_cpualloc (count)
   112  #define __CPU_FREE(cpuset) __sched_cpufree (cpuset)
   113  
   114  __BEGIN_DECLS extern int __sched_cpucount(size_t __setsize, const cpu_set_t * __setp) __THROW;
   115  extern cpu_set_t *__sched_cpualloc(size_t __count)
   116  __THROW __wur;
   117  extern void __sched_cpufree(cpu_set_t * __set) __THROW;
   118  
   119  __END_DECLS
   120  #endif				/* bits/cpu-set.h */