From 0ce916961b06a4aa61ae14f6a34c6f1ff99018df Mon Sep 17 00:00:00 2001 From: Michael Fairley Date: Tue, 16 May 2017 17:21:03 -0500 Subject: [PATCH] Don't try to stop the runloop until it's definitely running --- src/fsevent.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/fsevent.rs b/src/fsevent.rs index a94f9b59..29addd0c 100644 --- a/src/fsevent.rs +++ b/src/fsevent.rs @@ -85,6 +85,10 @@ struct StreamContextInfo { recursive_info: HashMap, } +extern "C" { + pub fn CFRunLoopIsWaiting(runloop: cf::CFRunLoopRef) -> bool; +} + impl FsEventWatcher { #[inline] fn is_running(&self) -> bool { @@ -99,6 +103,11 @@ impl FsEventWatcher { if let Some(runloop) = self.runloop { unsafe { let runloop = runloop as *mut libc::c_void; + + while !CFRunLoopIsWaiting(runloop) { + thread::yield_now(); + } + cf::CFRunLoopStop(runloop); } }