Improve event loop on NS so that no polling is used.
authorJan Djärv <jan.h.d@swipnet.se>
Wed, 15 Aug 2012 18:58:19 +0000 (20:58 +0200)
committerJan Djärv <jan.h.d@swipnet.se>
Wed, 15 Aug 2012 18:58:19 +0000 (20:58 +0200)
commitddee65158cd55a0c045a1ebc26f8ff73768cdc64
tree3ec8cde41573810900d76832751badde8c57f41e
parentac4845a68bf3ee0a0b4b88c292207d9738b981bd
Improve event loop on NS so that no polling is used.

* nsmenu.m (popupSession): Remove.
(pop_down_menu): Remove endModalSession.
(timeout_handler:): New method.
(runDialogAt:): Get next timeout.  Start a NSTimer with that timeout.
Call runModalForWindow.  Check timer_fired when it returns.
If not set, cancel timer and break out of loop.
Otherwise loop again, with a new timeout.

* nsterm.h (EmacsApp): fd_handler takes id argument.
(EmacsDialogPanel): Add timer_fired and timeout_handler.

* nsterm.m: Include fcntl.h if present.
(fd_entry, t_readfds, inNsSelect): Remove.
(select_writefds, select_valid, select_timeout, selfds)
(select_mutex, apploopnr): Add.
(EV_TRAILER): Call kbd_buffer_store_event_hold only if q_event_ptr.
Otherwise call kbd_buffer_store_event.
(ns_send_appdefined): Remove release of fd_entry.
(ns_read_socket): Always send appdefined.  Remove inNsSelect check.
Increment and decrement apploopnr.
(ns_select): If no file descriptors, just do a NSTimer.
Otherwise copy read/write masks and start select thread (fd_handler).
Start main loop and wait for application defined event.
Inform select thread to stop selecting after main loop is exited.
(ns_term_init): Create selfds pipe and set non-blocking.
Initialize select_mutex. Start the select thread (fd_handler).
(fd_handler:): Loop forever, wait for info from the main thread
to either start or stop selecting.  When select returns, send
and appdefined event.
(sendScrollEventAtLoc:fromEvent:): Check if q_event_ptr is set.
If not call kbd_buffer_store_event.
src/ChangeLog
src/nsmenu.m
src/nsterm.h
src/nsterm.m