urcu/tls-compat.h urcu/debug.h
nobase_nodist_include_HEADERS = urcu/arch.h urcu/uatomic.h urcu/config.h
-dist_noinst_HEADERS = urcu-die.h urcu-wait.h
+dist_noinst_HEADERS = urcu-die.h urcu-wait.h compat-getcpu.h
EXTRA_DIST = $(top_srcdir)/urcu/arch/*.h $(top_srcdir)/urcu/uatomic/*.h \
gpl-2.0.txt lgpl-2.1.txt lgpl-relicensing.txt \
--- /dev/null
+#ifndef _COMPAT_GETCPU_H
+#define _COMPAT_GETCPU_H
+
+/*
+ * compat-getcpu.h
+ *
+ * Copyright (c) 2015 Michael Jeanson <mjeanson@efficios.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <config.h>
+
+#if defined(HAVE_SCHED_GETCPU)
+#include <sched.h>
+
+static inline
+int urcu_sched_getcpu(void)
+{
+ return sched_getcpu();
+}
+#elif defined(HAVE_GETCPUID)
+#include <sys/processor.h>
+
+static inline
+int urcu_sched_getcpu(void)
+{
+ return (int) getcpuid();
+}
+#else
+
+static inline
+int urcu_sched_getcpu(void)
+{
+ return -1;
+}
+#endif
+
+#endif /* _COMPAT_GETCPU_H */
AC_FUNC_MALLOC
AC_FUNC_MMAP
AC_CHECK_FUNCS(
- [memset gettimeofday munmap sched_getcpu strtoul sysconf gettid memeset strerror]
+ [memset gettimeofday munmap sched_getcpu getcpuid strtoul sysconf gettid memeset strerror]
)
# Check for headers
#include <sched.h>
#include "config.h"
+#include "compat-getcpu.h"
#include <urcu.h>
#include <urcu-call-rcu.h>
#include <urcu-flavor.h>
poison_free(ht->split_count);
}
-#if defined(HAVE_SCHED_GETCPU)
static
int ht_get_split_count_index(unsigned long hash)
{
int cpu;
assert(split_count_mask >= 0);
- cpu = sched_getcpu();
+ cpu = urcu_sched_getcpu();
if (caa_unlikely(cpu < 0))
return hash & split_count_mask;
else
return cpu & split_count_mask;
}
-#else /* #if defined(HAVE_SCHED_GETCPU) */
-static
-int ht_get_split_count_index(unsigned long hash)
-{
- return hash & split_count_mask;
-}
-#endif /* #else #if defined(HAVE_SCHED_GETCPU) */
static
void ht_count_add(struct cds_lfht *ht, unsigned long size, unsigned long hash)
#include <sched.h>
#include "config.h"
+#include "compat-getcpu.h"
#include "urcu/wfcqueue.h"
#include "urcu-call-rcu.h"
#include "urcu-pointer.h"
* CPUs rather than only to specific threads.
*/
-#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)
+#if defined(HAVE_SYSCONF) && (defined(HAVE_SCHED_GETCPU) || defined(HAVE_GETCPUID))
/*
* Pointer to array of pointers to per-CPU call_rcu_data structures