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