#include "include/mempool.h"
#include "include/demangle.h"
-#ifndef _GNU_SOURCE
+#if defined(_GNU_SOURCE) && defined(WITH_SEASTAR) && !defined(WITH_ALIEN)
+#else
// Thread local variables should save index, not &shard[index],
// because shard[] is defined in the class
static thread_local size_t thread_shard_index = mempool::num_shards;
void mempool::pool_t::adjust_count(ssize_t items, ssize_t bytes)
{
-#ifndef _GNU_SOURCE
+#if defined(_GNU_SOURCE) && defined(WITH_SEASTAR) && !defined(WITH_ALIEN)
+ // the expected path: we alway pick the shard for a cpu core
+ // a thread is executing on.
+ const size_t shard_index = pick_a_shard_int();
+#else
// fallback for lack of sched_getcpu()
const size_t shard_index = []() {
if (thread_shard_index == num_shards) {
}
return thread_shard_index;
}();
-#else
- // the expected path: we alway pick the shard for a cpu core
- // a thread is executing on.
- const size_t shard_index = pick_a_shard_int();
#endif
shard[shard_index].items += items;
shard[shard_index].bytes += bytes;
#include <boost/container/flat_set.hpp>
#include <boost/container/flat_map.hpp>
-#ifdef _GNU_SOURCE
+#if defined(_GNU_SOURCE) && defined(WITH_SEASTAR) && !defined(WITH_ALIEN)
# include <sched.h>
#endif
};
static size_t pick_a_shard_int() {
-#ifndef _GNU_SOURCE
- // Dirt cheap, see:
- // https://fossies.org/dox/glibc-2.32/pthread__self_8c_source.html
- size_t me = (size_t)pthread_self();
- size_t i = (me >> CEPH_PAGE_SHIFT) & ((1 << num_shard_bits) - 1);
- return i;
-#else
+#if defined(_GNU_SOURCE) && defined(WITH_SEASTAR) && !defined(WITH_ALIEN)
// a thread local storage is actually just an approximation;
// what we truly want is a _cpu local storage_.
//
// a syscall-handled-in-userspace (vdso!). it grabs the cpu
// id kernel exposes to a task on context switch.
return sched_getcpu() & ((1 << num_shard_bits) - 1);
+#else
+ // Dirt cheap, see:
+ // https://fossies.org/dox/glibc-2.32/pthread__self_8c_source.html
+ size_t me = (size_t)pthread_self();
+ size_t i = (me >> CEPH_PAGE_SHIFT) & ((1 << num_shard_bits) - 1);
+ return i;
#endif
}