From 254ebaf34ca0a7c18da1efbc561a1985d815b2d1 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Fri, 22 Feb 2013 08:35:37 -0500 Subject: [PATCH] Fix build on architectures with HAVE_SCHED_GETCPU but without HAVE_SYSCONF Noticed on: https://buildd.debian.org/status/package.php?p=liburcu Tail of log for liburcu on kfreebsd-amd64: CC urcu.lo In file included from urcu.c:450:0: urcu-call-rcu-impl.h:145:12: error: static declaration of 'sched_getcpu' follows non-static declaration In file included from /usr/include/sched.h:43:0, from /usr/include/pthread.h:20, from urcu.c:30: /usr/include/x86_64-kfreebsd-gnu/bits/sched.h:65:12: note: previous declaration of 'sched_getcpu' was here make[3]: *** [urcu.lo] Error 1 make[3]: Leaving directory `/build/buildd-liburcu_0.7.6-1-kfreebsd-amd64-nnkICd/liburcu-0.7.6' make[2]: *** [all-recursive] Error 1 make[2]: Leaving directory `/build/buildd-liburcu_0.7.6-1-kfreebsd-amd64-nnkICd/liburcu-0.7.6' make[1]: *** [all] Error 2 make[1]: Leaving directory `/build/buildd-liburcu_0.7.6-1-kfreebsd-amd64-nnkICd/liburcu-0.7.6' dh_auto_build: make -j1 returned exit code 2 make: *** [build-arch] Error 2 Tail of log for liburcu on kfreebsd-i386: CC urcu.lo In file included from urcu.c:450:0: urcu-call-rcu-impl.h:145:12: error: static declaration of 'sched_getcpu' follows non-static declaration In file included from /usr/include/sched.h:43:0, from /usr/include/pthread.h:20, from urcu.c:30: /usr/include/i386-kfreebsd-gnu/bits/sched.h:65:12: note: previous declaration of 'sched_getcpu' was here make[3]: *** [urcu.lo] Error 1 make[3]: Leaving directory `/build/buildd-liburcu_0.7.6-1-kfreebsd-i386-sWzNKU/liburcu-0.7.6' make[2]: *** [all-recursive] Error 1 make[2]: Leaving directory `/build/buildd-liburcu_0.7.6-1-kfreebsd-i386-sWzNKU/liburcu-0.7.6' make[1]: *** [all] Error 2 make[1]: Leaving directory `/build/buildd-liburcu_0.7.6-1-kfreebsd-i386-sWzNKU/liburcu-0.7.6' dh_auto_build: make -j1 returned exit code 2 make: *** [build-arch] Error 2 Signed-off-by: Mathieu Desnoyers --- urcu-call-rcu-impl.h | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/urcu-call-rcu-impl.h b/urcu-call-rcu-impl.h index 0cc2ba2..04f7798 100644 --- a/urcu-call-rcu-impl.h +++ b/urcu-call-rcu-impl.h @@ -81,7 +81,23 @@ static struct call_rcu_data *default_call_rcu_data; * CPUs rather than only to specific threads. */ -#if defined(HAVE_SCHED_GETCPU) && defined(HAVE_SYSCONF) +#ifdef HAVE_SCHED_GETCPU + +static int urcu_sched_getcpu(void) +{ + return sched_getcpu(); +} + +#else /* #ifdef HAVE_SCHED_GETCPU */ + +static int urcu_sched_getcpu(void) +{ + return -1; +} + +#endif /* #else #ifdef HAVE_SCHED_GETCPU */ + +#if defined(HAVE_SYSCONF) && defined(HAVE_SCHED_GETCPU) /* * Pointer to array of pointers to per-CPU call_rcu_data structures @@ -124,7 +140,7 @@ static void alloc_cpu_call_rcu_data(void) } } -#else /* #if defined(HAVE_SCHED_GETCPU) && defined(HAVE_SYSCONF) */ +#else /* #if defined(HAVE_SYSCONF) && defined(HAVE_SCHED_GETCPU) */ /* * per_cpu_call_rcu_data should be constant, but some functions below, used both @@ -142,12 +158,7 @@ static void alloc_cpu_call_rcu_data(void) { } -static int sched_getcpu(void) -{ - return -1; -} - -#endif /* #else #if defined(HAVE_SCHED_GETCPU) && defined(HAVE_SYSCONF) */ +#endif /* #else #if defined(HAVE_SYSCONF) && defined(HAVE_SCHED_GETCPU) */ /* Acquire the specified pthread mutex. */ @@ -350,7 +361,7 @@ static void call_rcu_data_init(struct call_rcu_data **crdpp, * Return a pointer to the call_rcu_data structure for the specified * CPU, returning NULL if there is none. We cannot automatically * created it because the platform we are running on might not define - * sched_getcpu(). + * urcu_sched_getcpu(). * * The call to this function and use of the returned call_rcu_data * should be protected by RCU read-side lock. @@ -492,7 +503,7 @@ struct call_rcu_data *get_call_rcu_data(void) return URCU_TLS(thread_call_rcu_data); if (maxcpus > 0) { - crd = get_cpu_call_rcu_data(sched_getcpu()); + crd = get_cpu_call_rcu_data(urcu_sched_getcpu()); if (crd) return crd; } -- 2.34.1