attempt to make input handling a bit more power efficient on no activity

This commit is contained in:
Matthew 2025-10-06 07:00:48 +11:00
parent 92c4f8eb66
commit 4f3082f71d
2 changed files with 31 additions and 3 deletions

View File

@ -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*)&notify);
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();
}
}
}
}

10
util.d
View File

@ -23,6 +23,16 @@ Int3()
}
}
pragma(inline) void
Pause()
{
asm
{
rep;
nop;
}
}
pragma(inline) bool
CondIncr(i64 step, T)(bool cond, T* val)
{