Panic if the user attempts to run an event loop on a non-main thread on macOS

This commit is contained in:
mitchmindtree 2017-02-04 02:55:42 +11:00
parent ea19409960
commit fd0ddee63c

View file

@ -47,6 +47,10 @@ impl EventsLoop {
where F: FnMut(Event), where F: FnMut(Event),
{ {
unsafe { unsafe {
if !msg_send![cocoa::base::class("NSThread"), isMainThread] {
panic!("Events can only be polled from the main thread on macOS");
}
self.store_callback(callback); self.store_callback(callback);
} }
@ -94,6 +98,10 @@ impl EventsLoop {
self.interrupted.store(false, std::sync::atomic::Ordering::Relaxed); self.interrupted.store(false, std::sync::atomic::Ordering::Relaxed);
unsafe { unsafe {
if !msg_send![cocoa::base::class("NSThread"), isMainThread] {
panic!("Events can only be polled from the main thread on macOS");
}
self.store_callback(callback); self.store_callback(callback);
} }