Skip to content

Commit 03ddeeb

Browse files
committed
added fallback sleep when query thread is not in use
1 parent 72d1ea0 commit 03ddeeb

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

src/app/tile.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,11 +692,12 @@ fn metadata_query_thread(
692692
let run_loop = NSRunLoop::currentRunLoop();
693693
let run_loop_mode = unsafe { NSDefaultRunLoopMode };
694694
let tick_seconds: f64 = 0.05;
695+
let idle_sleep = Duration::from_millis((tick_seconds * 1000.0) as u64);
695696

696697
loop {
697698
// Tick the run loop to process notifications.
698699
let timeout = NSDate::dateWithTimeIntervalSinceNow(tick_seconds);
699-
run_loop.runMode_beforeDate(run_loop_mode, &timeout);
700+
let handled_source = run_loop.runMode_beforeDate(run_loop_mode, &timeout);
700701

701702
// Drain results only when the finish-gathering notification has fired.
702703
if results_ready.swap(false, Ordering::AcqRel) {
@@ -735,6 +736,12 @@ fn metadata_query_thread(
735736
if msg_tx.is_closed() {
736737
break;
737738
}
739+
740+
// NSRunLoop can return immediately when no input sources/timers are active.
741+
// Without this guard, the thread can busy-spin and consume a full core.
742+
if !handled_source {
743+
std::thread::sleep(idle_sleep);
744+
}
738745
}
739746

740747
query.stopQuery();

0 commit comments

Comments
 (0)