[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master 3bd2e9e: Remove NSEvent loop from ns_select (bug#25
From: |
Alan Third |
Subject: |
[Emacs-diffs] master 3bd2e9e: Remove NSEvent loop from ns_select (bug#25265) |
Date: |
Mon, 6 Mar 2017 14:58:39 -0500 (EST) |
branch: master
commit 3bd2e9e975ed29daaf03ca7559e4664aade0674f
Author: Alan Third <address@hidden>
Commit: Alan Third <address@hidden>
Remove NSEvent loop from ns_select (bug#25265)
* src/nsterm.m (ns_select): Remove event processing loop and replace
with simple test for a new event.
---
src/nsterm.m | 76 ++++++++++++++++++++++++++++--------------------------------
1 file changed, 36 insertions(+), 40 deletions(-)
diff --git a/src/nsterm.m b/src/nsterm.m
index 08ee0cd..ebe29e4 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -4108,6 +4108,9 @@ ns_select (int nfds, fd_set *readfds, fd_set *writefds,
struct input_event event;
char c;
+ NSDate *timeout_date = nil;
+ NSEvent *ns_event;
+
NSTRACE_WHEN (NSTRACE_GROUP_EVENTS, "ns_select");
#ifdef HAVE_NATIVE_FS
@@ -4170,65 +4173,58 @@ ns_select (int nfds, fd_set *readfds, fd_set *writefds,
{
/* No file descriptor, just a timeout, no need to wake fd_handler */
double time = timespectod (*timeout);
- timed_entry = [[NSTimer scheduledTimerWithTimeInterval: time
- target: NSApp
- selector:
- @selector (timeout_handler:)
- userInfo: 0
- repeats: NO]
- retain];
- }
- else /* No timeout and no file descriptors, can this happen? */
- {
- /* Send appdefined so we exit from the loop */
- ns_send_appdefined (-1);
+ timeout_date = [NSDate dateWithTimeIntervalSinceNow: time];
}
- block_input ();
- ns_init_events (&event);
-
- [NSApp run];
+ /* Listen for a new NSEvent. */
+ ns_event = [NSApp nextEventMatchingMask: NSEventMaskAny
+ untilDate: timeout_date
+ inMode: NSDefaultRunLoopMode
+ dequeue: NO];
- ns_finish_events ();
if (nr > 0 && readfds)
{
c = 's';
emacs_write_sig (selfds[1], &c, 1);
}
- unblock_input ();
-
- t = last_appdefined_event_data;
- if (t != NO_APPDEFINED_DATA)
+ if (ns_event != nil)
{
- last_appdefined_event_data = NO_APPDEFINED_DATA;
-
- if (t == -2)
+ if ([ns_event type] == NSEventTypeApplicationDefined)
{
- /* The NX_APPDEFINED event we received was a timeout. */
- result = 0;
+ if ([ns_event data1] < 0)
+ {
+ /* The NX_APPDEFINED event we received was a timeout. */
+ result = 0;
+ }
+ else
+ {
+ /* Received back from select () in fd_handler; copy the results
*/
+ pthread_mutex_lock (&select_mutex);
+ if (readfds) *readfds = select_readfds;
+ if (writefds) *writefds = select_writefds;
+ pthread_mutex_unlock (&select_mutex);
+ result = [ns_event data1];
+ }
+
+ /* Remove the NX_APPDEFINED event from the queue as it's no
+ longer needed. */
+ [NSApp nextEventMatchingMask: NSEventMaskAny
+ untilDate: nil
+ inMode: NSDefaultRunLoopMode
+ dequeue: YES];
}
- else if (t == -1)
+ else
{
- /* The NX_APPDEFINED event we received was the result of
- at least one real input event arriving. */
+ /* A real NSEvent came in. */
errno = EINTR;
result = -1;
}
- else
- {
- /* Received back from select () in fd_handler; copy the results */
- pthread_mutex_lock (&select_mutex);
- if (readfds) *readfds = select_readfds;
- if (writefds) *writefds = select_writefds;
- pthread_mutex_unlock (&select_mutex);
- result = t;
- }
}
else
{
- errno = EINTR;
- result = -1;
+ /* Reading from the NSEvent queue timed out. */
+ result = 0;
}
return result;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] master 3bd2e9e: Remove NSEvent loop from ns_select (bug#25265),
Alan Third <=