@@ -639,6 +639,52 @@ pub unsafe extern "C" fn fff_wait_for_scan(
639639 FffResult :: ok_int ( 1 )
640640}
641641
642+ /// Wait for the background file watcher to be ready.
643+ ///
644+ /// The watcher is created after the initial scan, git status, and optional
645+ /// warmup phases complete. Returns 1 if the watcher is ready, 0 if timed out.
646+ ///
647+ /// ## Safety
648+ /// `fff_handle` must be a valid instance pointer from `fff_create_instance`.
649+ #[ unsafe( no_mangle) ]
650+ pub unsafe extern "C" fn fff_wait_for_watcher (
651+ fff_handle : * mut c_void ,
652+ timeout_ms : u64 ,
653+ ) -> * mut FffResult {
654+ let inst = match unsafe { instance_ref ( fff_handle) } {
655+ Ok ( i) => i,
656+ Err ( e) => return e,
657+ } ;
658+
659+ let watcher_signal = {
660+ let guard = match inst. picker . read ( ) {
661+ Ok ( g) => g,
662+ Err ( e) => return FffResult :: err ( & format ! ( "Failed to acquire file picker lock: {}" , e) ) ,
663+ } ;
664+
665+ let picker = match guard. as_ref ( ) {
666+ Some ( p) => p,
667+ None => return FffResult :: err ( "File picker not initialized" ) ,
668+ } ;
669+
670+ picker. watcher_signal ( )
671+ } ;
672+
673+ let timeout = Duration :: from_millis ( timeout_ms) ;
674+ let start = std:: time:: Instant :: now ( ) ;
675+ let mut sleep_duration = Duration :: from_millis ( 1 ) ;
676+
677+ while !watcher_signal. load ( std:: sync:: atomic:: Ordering :: Acquire ) {
678+ if start. elapsed ( ) >= timeout {
679+ return FffResult :: ok_int ( 0 ) ;
680+ }
681+ std:: thread:: sleep ( sleep_duration) ;
682+ sleep_duration = std:: cmp:: min ( sleep_duration * 2 , Duration :: from_millis ( 50 ) ) ;
683+ }
684+
685+ FffResult :: ok_int ( 1 )
686+ }
687+
642688/// Restart indexing in a new directory.
643689///
644690/// ## Safety
0 commit comments