File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ( ) ;
You can’t perform that action at this time.
0 commit comments