cpu.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2022 The Squid Software Foundation and contributors
3  *
4  * Squid software is distributed under GPLv2+ license and includes
5  * contributions from numerous individuals and organizations.
6  * Please see the COPYING and CONTRIBUTORS files for details.
7  */
8 
9 #ifndef SQUID_COMPAT_CPU_H
10 #define SQUID_COMPAT_CPU_H
11 
12 #if HAVE_ERRNO_H
13 #include <errno.h> /* for ENOTSUP */
14 #endif
15 #if HAVE_SCHED_H
16 #include <sched.h>
17 #endif
18 
19 #if !HAVE_CPU_AFFINITY
20 /* failing replacements to minimize the number of if-HAVE_CPU_AFFINITYs */
21 #if !HAVE_CPU_SET_T
22 typedef struct {
23  int bits;
24 } cpu_set_t;
25 #endif
26 inline int sched_setaffinity(int, size_t, cpu_set_t *) { return ENOTSUP; }
27 inline int sched_getaffinity(int, size_t, cpu_set_t *) { return ENOTSUP; }
28 #endif /* HAVE_CPU_AFFINITY */
29 
30 #if !defined(CPU_SETSIZE)
31 #define CPU_SETSIZE 0
32 #endif
33 
34 #if !defined(CPU_ZERO)
35 #define CPU_ZERO(set) (void)0
36 #endif
37 
38 #if !defined(CPU_SET)
39 #define CPU_SET(cpunum, cpuset) CpuSet(cpunum, cpuset)
40 inline void CpuSet(int, const cpu_set_t *) {}
41 #endif
42 
43 #if !defined(CPU_CLR)
44 #define CPU_CLR(cpu, set) (void)0
45 #endif
46 
47 #if !defined(CPU_ISSET)
48 #define CPU_ISSET(cpunum, cpuset) CpuIsSet(cpunum, cpuset)
49 inline bool CpuIsSet(int, const cpu_set_t *) { return false; }
50 #endif
51 
52 // glibc prior to 2.6 lacks CPU_COUNT
53 #ifndef CPU_COUNT
54 #define CPU_COUNT(set) CpuCount(set)
55 inline int
57 CpuCount(const cpu_set_t *set)
58 {
59  int count = 0;
60  for (int i = 0; i < CPU_SETSIZE; ++i) {
61  if (CPU_ISSET(i, set))
62  ++count;
63  }
64  return count;
65 }
66 #endif /* CPU_COUNT */
67 
68 // glibc prior to 2.7 lacks CPU_AND
69 #ifndef CPU_AND
70 #define CPU_AND(destset, srcset1, srcset2) CpuAnd((destset), (srcset1), (srcset2))
71 inline void
73 CpuAnd(cpu_set_t *destset, const cpu_set_t *srcset1, const cpu_set_t *srcset2)
74 {
75  for (int i = 0; i < CPU_SETSIZE; ++i) {
76  if (CPU_ISSET(i, srcset1) && CPU_ISSET(i, srcset2))
77  CPU_SET(i, destset);
78  else
79  CPU_CLR(i, destset);
80  }
81 }
82 #endif /* CPU_AND */
83 
84 #endif /* SQUID_COMPAT_CPU_H */
85 
bool CpuIsSet(int, const cpu_set_t *)
Definition: cpu.h:49
void CpuAnd(cpu_set_t *destset, const cpu_set_t *srcset1, const cpu_set_t *srcset2)
CPU_AND replacement.
Definition: cpu.h:73
int sched_getaffinity(int, size_t, cpu_set_t *)
Definition: cpu.h:27
void CpuSet(int, const cpu_set_t *)
Definition: cpu.h:40
int sched_setaffinity(int, size_t, cpu_set_t *)
Definition: cpu.h:26
#define CPU_ISSET(cpunum, cpuset)
Definition: cpu.h:48
#define CPU_SET(cpunum, cpuset)
Definition: cpu.h:39
#define CPU_SETSIZE
Definition: cpu.h:31
#define CPU_CLR(cpu, set)
Definition: cpu.h:44
int CpuCount(const cpu_set_t *set)
CPU_COUNT replacement.
Definition: cpu.h:57
Definition: cpu.h:22
int bits
Definition: cpu.h:23

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors