aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2011-08-01 18:49:16 -0300
committerArnaldo Carvalho de Melo <acme@redhat.com>2011-08-01 19:11:24 -0300
commit36e377da2e521207971f6c6aba60e090e384b843 (patch)
tree20c9980a38ed81d0e6b39176cd9421e9ab179b33
parent6b9f411948d84e4cafd439dc1865b99247bfe5ea (diff)
downloadpython-schedutils-36e377da2e521207971f6c6aba60e090e384b843.tar.gz
CPU_ALLOC macros are not present in older systems
So add an implementation from glibc-headers-2.12-1.7.el6.x86_64. Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--python-schedutils/schedutils.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/python-schedutils/schedutils.c b/python-schedutils/schedutils.c
index a3cbce3..c6cc6fd 100644
--- a/python-schedutils/schedutils.c
+++ b/python-schedutils/schedutils.c
@@ -7,6 +7,58 @@
#define __unused __attribute__ ((unused))
#endif
+#ifndef CPU_ALLOC
+
+/* From glibc-headers-2.12-1.7.el6.x86_64 */
+
+/* Basic access functions. */
+#define __CPUELT(cpu) ((cpu) / __NCPUBITS)
+#define __CPUMASK(cpu) ((__cpu_mask) 1 << ((cpu) % __NCPUBITS))
+
+#define CPU_ALLOC_SIZE(ncpus) \
+ ((((ncpus) + __NCPUBITS - 1) / __NCPUBITS) * sizeof (__cpu_mask))
+
+/* Access functions for CPU masks. */
+# if __GNUC_PREREQ (2, 91)
+# define __CPU_ZERO_S(setsize, cpusetp) \
+ do __builtin_memset (cpusetp, '\0', setsize); while (0)
+# else
+# define __CPU_ZERO_S(setsize, cpusetp) \
+ do { \
+ size_t __i; \
+ size_t __imax = (setsize) / sizeof (__cpu_mask); \
+ __cpu_mask *__bits = (cpusetp)->__bits; \
+ for (__i = 0; __i < __imax; ++__i) \
+ __bits[__i] = 0; \
+ } while (0)
+# endif
+
+#define CPU_FREE(cpus) free(cpus)
+#define CPU_ALLOC(ncpus) malloc(CPU_ALLOC_SIZE(ncpus))
+
+# define __CPU_SET_S(cpu, setsize, cpusetp) \
+ (__extension__ \
+ ({ size_t __cpu = (cpu); \
+ __cpu < 8 * (setsize) \
+ ? (((__cpu_mask *) ((cpusetp)->__bits))[__CPUELT (__cpu)] \
+ |= __CPUMASK (__cpu)) \
+ : 0; }))
+
+# define __CPU_ISSET_S(cpu, setsize, cpusetp) \
+ (__extension__ \
+ ({ size_t __cpu = (cpu); \
+ __cpu < 8 * (setsize) \
+ ? ((((__const __cpu_mask *) ((cpusetp)->__bits))[__CPUELT (__cpu)] \
+ & __CPUMASK (__cpu))) != 0 \
+ : 0; }))
+
+#define CPU_SET_S(cpu, setsize, cpusetp) __CPU_SET_S (cpu, setsize, cpusetp)
+#define CPU_ISSET_S(cpu, setsize, cpusetp) __CPU_ISSET_S (cpu, setsize, cpusetp)
+#define CPU_ZERO_S(setsize, cpusetp) __CPU_ZERO_S (setsize, cpusetp)
+
+#endif /* CPU_ALLOC */
+
+
#ifndef SCHED_RESET_ON_FORK
#define SCHED_RESET_ON_FORK 0x40000000
#endif