]>
Commit | Line | Data |
---|---|---|
37be9888 | 1 | /* |
ef57eb7b | 2 | * Copyright (C) 1996-2016 The Squid Software Foundation and contributors |
37be9888 AJ |
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 | ||
96c2bb61 AR |
9 | #ifndef SQUID_COMPAT_CPU_H |
10 | #define SQUID_COMPAT_CPU_H | |
11 | ||
9d13527a AJ |
12 | #if HAVE_ERRNO_H |
13 | #include <errno.h> /* for ENOTSUP */ | |
14 | #endif | |
96c2bb61 AR |
15 | #if HAVE_SCHED_H |
16 | #include <sched.h> | |
17 | #endif | |
18 | ||
9d13527a AJ |
19 | #if !HAVE_CPU_AFFINITY |
20 | /* failing replacements to minimize the number of if-HAVE_CPU_AFFINITYs */ | |
e51a90df | 21 | #if !defined(__cpu_set_t_defined) |
9d13527a AJ |
22 | typedef struct { |
23 | int bits; | |
24 | } cpu_set_t; | |
e51a90df | 25 | #endif |
9d13527a AJ |
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(cpu, set) (void)0 | |
40 | #endif | |
41 | ||
42 | #if !defined(CPU_CLR) | |
43 | #define CPU_CLR(cpu, set) (void)0 | |
44 | #endif | |
45 | ||
fe3bffac AJ |
46 | #if !defined(CPU_ISSET) |
47 | #define CPU_ISSET(cpu, set) false | |
48 | #endif | |
49 | ||
96c2bb61 AR |
50 | // glibc prior to 2.6 lacks CPU_COUNT |
51 | #ifndef CPU_COUNT | |
52 | #define CPU_COUNT(set) CpuCount(set) | |
53 | /// CPU_COUNT replacement | |
54 | inline int | |
55 | CpuCount(const cpu_set_t *set) | |
56 | { | |
57 | int count = 0; | |
58 | for (int i = 0; i < CPU_SETSIZE; ++i) { | |
59 | if (CPU_ISSET(i, set)) | |
60 | ++count; | |
61 | } | |
62 | return count; | |
63 | } | |
64 | #endif /* CPU_COUNT */ | |
65 | ||
66 | // glibc prior to 2.7 lacks CPU_AND | |
67 | #ifndef CPU_AND | |
68 | #define CPU_AND(destset, srcset1, srcset2) CpuAnd((destset), (srcset1), (srcset2)) | |
69 | /// CPU_AND replacement | |
70 | inline void | |
71 | CpuAnd(cpu_set_t *destset, const cpu_set_t *srcset1, const cpu_set_t *srcset2) | |
72 | { | |
96c2bb61 AR |
73 | for (int i = 0; i < CPU_SETSIZE; ++i) { |
74 | if (CPU_ISSET(i, srcset1) && CPU_ISSET(i, srcset2)) | |
75 | CPU_SET(i, destset); | |
7aba0fdb AR |
76 | else |
77 | CPU_CLR(i, destset); | |
96c2bb61 AR |
78 | } |
79 | } | |
80 | #endif /* CPU_AND */ | |
81 | ||
96c2bb61 | 82 | #endif /* SQUID_COMPAT_CPU_H */ |
f53969cc | 83 |