Hash table test: FreeBSD compatibility fix
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sun, 4 Mar 2012 20:41:43 +0000 (15:41 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sun, 4 Mar 2012 20:41:43 +0000 (15:41 -0500)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
tests/test_urcu_hash.c

index adeac3c27df7561ba065a2ab9aad89a0e0bd07e5..c8d8a89b411c4679b1e042f329571e2497f96aeb 100644 (file)
@@ -21,6 +21,7 @@
  */
 
 #define _GNU_SOURCE
+#include "../config.h"
 #include <stdio.h>
 #include <pthread.h>
 #include <stdlib.h>
@@ -32,6 +33,7 @@
 #include <assert.h>
 #include <sched.h>
 #include <errno.h>
+#include <signal.h>
 
 #ifdef __linux__
 #include <syscall.h>
@@ -187,6 +189,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;
@@ -196,6 +204,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");
@@ -209,7 +218,12 @@ static void set_affinity(void)
        }
        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 {
This page took 0.026242 seconds and 4 git commands to generate.