macos: clear runloop Option in sync with count

This commit is contained in:
Kevin Mehall 2023-12-24 10:41:22 -07:00
parent f9807a1876
commit cd8fcd90ca

View file

@ -51,11 +51,6 @@ pub(crate) fn add_event_source(source: CFRunLoopSource) -> EventRegistration {
runloop.add_source(&source.0, unsafe { kCFRunLoopCommonModes });
tx.send(SendCFRunLoop(runloop)).unwrap();
CFRunLoop::run_current();
// Remove the global if we exited the run loop
let mut el = EVENT_LOOP.lock().unwrap();
let _ = el.runloop.take();
el.count = 0;
info!("event loop thread exited");
});
event_loop.runloop = Some(rx.recv().expect("failed to start run loop thread"));
@ -78,6 +73,7 @@ impl Drop for EventRegistration {
if event_loop.count == 0 {
runloop.stop();
event_loop.runloop.take();
}
}
}