*/
#define _GNU_SOURCE
+#include "../config.h"
#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>
#include <assert.h>
#include <sched.h>
#include <errno.h>
+#include <signal.h>
#ifdef __linux__
#include <syscall.h>
pthread_mutex_t affinity_mutex = PTHREAD_MUTEX_INITIALIZER;
+#ifndef HAVE_CPU_SET_T
+typedef unsigned long cpu_set_t;
+# define CPU_ZERO(cpuset) do { *(cpuset) = 0; } while(0)
+# define CPU_SET(cpu, cpuset) do { *(cpuset) |= (1UL << (cpu)); } while(0)
+#endif
+
static void set_affinity(void)
{
cpu_set_t mask;
if (!use_affinity)
return;
+#if HAVE_SCHED_SETAFFINITY
ret = pthread_mutex_lock(&affinity_mutex);
if (ret) {
perror("Error in pthread mutex lock");
}
CPU_ZERO(&mask);
CPU_SET(cpu, &mask);
- sched_setaffinity(0, sizeof(mask), &mask);
+#if SCHED_SETAFFINITY_ARGS == 2
+ sched_setaffinity(0, &mask);
+#else
+ sched_setaffinity(0, sizeof(mask), &mask);
+#endif
+#endif /* HAVE_SCHED_SETAFFINITY */
}
static enum {