From 4f3082f71d5a877dc34163dac5f1b12a02d5a02c Mon Sep 17 00:00:00 2001 From: Matthew Date: Mon, 6 Oct 2025 07:00:48 +1100 Subject: [PATCH] attempt to make input handling a bit more power efficient on no activity --- platform.d | 24 +++++++++++++++++++++--- util.d | 10 ++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/platform.d b/platform.d index bf00ee1..59b6118 100644 --- a/platform.d +++ b/platform.d @@ -466,13 +466,22 @@ Wake(SysThread* thread) PThreadCondSignal(&thread.cond); } +void +Yield() +{ + version(linux) + { + import core.sys.posix.sched; + sched_yield(); + } +} + void Kill() { PThreadExit(null); } - void ResetInputs(Inputs* inputs) { @@ -1097,6 +1106,7 @@ HandleEvents(void* window_ptr) bool ignore_mouse_events = false; + u64 no_ev_count; for(;;) { if(w.close) @@ -1289,12 +1299,20 @@ HandleEvents(void* window_ptr) xcb_send_event(w.conn, false, req.requestor, XCB_EVENT_MASK_PROPERTY_CHANGE, cast(char*)¬ify); xcb_flush(w.conn); } break; - default: - break; + default: break; } ReturnInputs(w); } + else + { + no_ev_count += 1; + if(no_ev_count >= 5) + { + no_ev_count = 0; + Yield(); + } + } } } diff --git a/util.d b/util.d index a0a8442..d6608eb 100644 --- a/util.d +++ b/util.d @@ -23,6 +23,16 @@ Int3() } } +pragma(inline) void +Pause() +{ + asm + { + rep; + nop; + } +} + pragma(inline) bool CondIncr(i64 step, T)(bool cond, T* val) {