25#include <seastar/util/modules.hh>
32struct preemption_monitor {
36 std::atomic<uint32_t> head;
37 std::atomic<uint32_t> tail;
40#ifdef SEASTAR_BUILD_SHARED_LIBS
41const preemption_monitor*& get_need_preempt_var();
43inline const preemption_monitor*& get_need_preempt_var() {
44 static preemption_monitor bootstrap_preemption_monitor;
45 static thread_local const preemption_monitor* g_need_preempt = &bootstrap_preemption_monitor;
46 return g_need_preempt;
50void set_need_preempt_var(
const preemption_monitor* pm);
54monitor_need_preempt() noexcept {
56 std::atomic_signal_fence(std::memory_order_seq_cst);
57 auto np = internal::get_need_preempt_var();
60 auto head = np->head.load(std::memory_order_relaxed);
61 auto tail = np->tail.load(std::memory_order_relaxed);
64 return __builtin_expect(head != tail,
false);
70inline bool need_preempt() noexcept {
72 return internal::monitor_need_preempt();
87scheduler_need_preempt() {
89 return need_preempt();
98 static thread_local unsigned counter = 0;
99 return ++counter % 64 == 0 || monitor_need_preempt();;
Seastar API namespace.
Definition: abort_on_ebadf.hh:26