]> git.ipfire.org Git - thirdparty/squid.git/blob - compat/cpu.h
merge from SslServerCertValidator r12332
[thirdparty/squid.git] / compat / cpu.h
1 #ifndef SQUID_COMPAT_CPU_H
2 #define SQUID_COMPAT_CPU_H
3
4 #if HAVE_CPU_AFFINITY
5
6 #if HAVE_SCHED_H
7 #include <sched.h>
8 #endif
9
10 // glibc prior to 2.6 lacks CPU_COUNT
11 #ifndef CPU_COUNT
12 #define CPU_COUNT(set) CpuCount(set)
13 /// CPU_COUNT replacement
14 inline int
15 CpuCount(const cpu_set_t *set)
16 {
17 int count = 0;
18 for (int i = 0; i < CPU_SETSIZE; ++i) {
19 if (CPU_ISSET(i, set))
20 ++count;
21 }
22 return count;
23 }
24 #endif /* CPU_COUNT */
25
26 // glibc prior to 2.7 lacks CPU_AND
27 #ifndef CPU_AND
28 #define CPU_AND(destset, srcset1, srcset2) CpuAnd((destset), (srcset1), (srcset2))
29 /// CPU_AND replacement
30 inline void
31 CpuAnd(cpu_set_t *destset, const cpu_set_t *srcset1, const cpu_set_t *srcset2)
32 {
33 for (int i = 0; i < CPU_SETSIZE; ++i) {
34 if (CPU_ISSET(i, srcset1) && CPU_ISSET(i, srcset2))
35 CPU_SET(i, destset);
36 else
37 CPU_CLR(i, destset);
38 }
39 }
40 #endif /* CPU_AND */
41
42 #else /* HAVE_CPU_AFFINITY */
43
44 #if HAVE_ERRNO_H
45 #include <errno.h> /* for ENOTSUP */
46 #endif
47
48 /* failing replacements to minimize the number of if-HAVE_CPU_AFFINITYs */
49 typedef struct {
50 int bits;
51 } cpu_set_t;
52 #define CPU_SETSIZE 0
53 #define CPU_COUNT(set) 0
54 #define CPU_AND(destset, srcset1, srcset2) (void)0
55 #define CPU_ZERO(set) (void)0
56 #define CPU_SET(cpu, set) (void)0
57 #define CPU_CLR(cpu, set) (void)0
58 inline int sched_setaffinity(int, size_t, cpu_set_t *) { return ENOTSUP; }
59 inline int sched_getaffinity(int, size_t, cpu_set_t *) { return ENOTSUP; }
60
61 #endif /* HAVE_CPU_AFFINITY */
62
63 #endif /* SQUID_COMPAT_CPU_H */