Support earlier glibc sched_setaffinity
[urcu.git] / tests / test_rwlock.c
index 837b800df6c40b22b38fce0f249f6a0c9b294725..b8931008bfd6dd172b53f7f2dbde0ef8d683d885 100644 (file)
@@ -21,6 +21,7 @@
  */
 
 #define _GNU_SOURCE
+#include "../config.h"
 #include <stdio.h>
 #include <pthread.h>
 #include <stdlib.h>
@@ -98,6 +99,12 @@ static int use_affinity = 0;
 
 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;
@@ -107,6 +114,7 @@ static void set_affinity(void)
        if (!use_affinity)
                return;
 
+#if HAVE_SCHED_SETAFFINITY
        ret = pthread_mutex_lock(&affinity_mutex);
        if (ret) {
                perror("Error in pthread mutex lock");
@@ -118,9 +126,15 @@ static void set_affinity(void)
                perror("Error in pthread mutex unlock");
                exit(-1);
        }
+
        CPU_ZERO(&mask);
        CPU_SET(cpu, &mask);
+#if SCHED_SETAFFINITY_ARGS == 2
+       sched_setaffinity(0, &mask);
+#else
        sched_setaffinity(0, sizeof(mask), &mask);
+#endif
+#endif /* HAVE_SCHED_SETAFFINITY */
 }
 
 /*
This page took 0.022744 seconds and 4 git commands to generate.