diff options
| author | Alan Third | 2017-03-06 19:50:47 +0000 |
|---|---|---|
| committer | Alan Third | 2017-03-06 19:57:36 +0000 |
| commit | 3bd2e9e975ed29daaf03ca7559e4664aade0674f (patch) | |
| tree | 4bad701f3306f2987760220c282442a87eba7d55 /src | |
| parent | eae5dcd57d1a73688ccb576decbf90fa711105e7 (diff) | |
| download | emacs-3bd2e9e975ed29daaf03ca7559e4664aade0674f.tar.gz emacs-3bd2e9e975ed29daaf03ca7559e4664aade0674f.zip | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/nsterm.m | 76 |
1 files changed, 36 insertions, 40 deletions
diff --git a/src/nsterm.m b/src/nsterm.m index 08ee0cdf6fd..ebe29e42619 100644 --- a/src/nsterm.m +++ b/src/nsterm.m | |||
| @@ -4108,6 +4108,9 @@ ns_select (int nfds, fd_set *readfds, fd_set *writefds, | |||
| 4108 | struct input_event event; | 4108 | struct input_event event; |
| 4109 | char c; | 4109 | char c; |
| 4110 | 4110 | ||
| 4111 | NSDate *timeout_date = nil; | ||
| 4112 | NSEvent *ns_event; | ||
| 4113 | |||
| 4111 | NSTRACE_WHEN (NSTRACE_GROUP_EVENTS, "ns_select"); | 4114 | NSTRACE_WHEN (NSTRACE_GROUP_EVENTS, "ns_select"); |
| 4112 | 4115 | ||
| 4113 | #ifdef HAVE_NATIVE_FS | 4116 | #ifdef HAVE_NATIVE_FS |
| @@ -4170,65 +4173,58 @@ ns_select (int nfds, fd_set *readfds, fd_set *writefds, | |||
| 4170 | { | 4173 | { |
| 4171 | /* No file descriptor, just a timeout, no need to wake fd_handler */ | 4174 | /* No file descriptor, just a timeout, no need to wake fd_handler */ |
| 4172 | double time = timespectod (*timeout); | 4175 | double time = timespectod (*timeout); |
| 4173 | timed_entry = [[NSTimer scheduledTimerWithTimeInterval: time | 4176 | timeout_date = [NSDate dateWithTimeIntervalSinceNow: time]; |
| 4174 | target: NSApp | ||
| 4175 | selector: | ||
| 4176 | @selector (timeout_handler:) | ||
| 4177 | userInfo: 0 | ||
| 4178 | repeats: NO] | ||
| 4179 | retain]; | ||
| 4180 | } | ||
| 4181 | else /* No timeout and no file descriptors, can this happen? */ | ||
| 4182 | { | ||
| 4183 | /* Send appdefined so we exit from the loop */ | ||
| 4184 | ns_send_appdefined (-1); | ||
| 4185 | } | 4177 | } |
| 4186 | 4178 | ||
| 4187 | block_input (); | 4179 | /* Listen for a new NSEvent. */ |
| 4188 | ns_init_events (&event); | 4180 | ns_event = [NSApp nextEventMatchingMask: NSEventMaskAny |
| 4189 | 4181 | untilDate: timeout_date | |
| 4190 | [NSApp run]; | 4182 | inMode: NSDefaultRunLoopMode |
| 4183 | dequeue: NO]; | ||
| 4191 | 4184 | ||
| 4192 | ns_finish_events (); | ||
| 4193 | if (nr > 0 && readfds) | 4185 | if (nr > 0 && readfds) |
| 4194 | { | 4186 | { |
| 4195 | c = 's'; | 4187 | c = 's'; |
| 4196 | emacs_write_sig (selfds[1], &c, 1); | 4188 | emacs_write_sig (selfds[1], &c, 1); |
| 4197 | } | 4189 | } |
| 4198 | unblock_input (); | ||
| 4199 | |||
| 4200 | t = last_appdefined_event_data; | ||
| 4201 | 4190 | ||
| 4202 | if (t != NO_APPDEFINED_DATA) | 4191 | if (ns_event != nil) |
| 4203 | { | 4192 | { |
| 4204 | last_appdefined_event_data = NO_APPDEFINED_DATA; | 4193 | if ([ns_event type] == NSEventTypeApplicationDefined) |
| 4205 | |||
| 4206 | if (t == -2) | ||
| 4207 | { | 4194 | { |
| 4208 | /* The NX_APPDEFINED event we received was a timeout. */ | 4195 | if ([ns_event data1] < 0) |
| 4209 | result = 0; | 4196 | { |
| 4197 | /* The NX_APPDEFINED event we received was a timeout. */ | ||
| 4198 | result = 0; | ||
| 4199 | } | ||
| 4200 | else | ||
| 4201 | { | ||
| 4202 | /* Received back from select () in fd_handler; copy the results */ | ||
| 4203 | pthread_mutex_lock (&select_mutex); | ||
| 4204 | if (readfds) *readfds = select_readfds; | ||
| 4205 | if (writefds) *writefds = select_writefds; | ||
| 4206 | pthread_mutex_unlock (&select_mutex); | ||
| 4207 | result = [ns_event data1]; | ||
| 4208 | } | ||
| 4209 | |||
| 4210 | /* Remove the NX_APPDEFINED event from the queue as it's no | ||
| 4211 | longer needed. */ | ||
| 4212 | [NSApp nextEventMatchingMask: NSEventMaskAny | ||
| 4213 | untilDate: nil | ||
| 4214 | inMode: NSDefaultRunLoopMode | ||
| 4215 | dequeue: YES]; | ||
| 4210 | } | 4216 | } |
| 4211 | else if (t == -1) | 4217 | else |
| 4212 | { | 4218 | { |
| 4213 | /* The NX_APPDEFINED event we received was the result of | 4219 | /* A real NSEvent came in. */ |
| 4214 | at least one real input event arriving. */ | ||
| 4215 | errno = EINTR; | 4220 | errno = EINTR; |
| 4216 | result = -1; | 4221 | result = -1; |
| 4217 | } | 4222 | } |
| 4218 | else | ||
| 4219 | { | ||
| 4220 | /* Received back from select () in fd_handler; copy the results */ | ||
| 4221 | pthread_mutex_lock (&select_mutex); | ||
| 4222 | if (readfds) *readfds = select_readfds; | ||
| 4223 | if (writefds) *writefds = select_writefds; | ||
| 4224 | pthread_mutex_unlock (&select_mutex); | ||
| 4225 | result = t; | ||
| 4226 | } | ||
| 4227 | } | 4223 | } |
| 4228 | else | 4224 | else |
| 4229 | { | 4225 | { |
| 4230 | errno = EINTR; | 4226 | /* Reading from the NSEvent queue timed out. */ |
| 4231 | result = -1; | 4227 | result = 0; |
| 4232 | } | 4228 | } |
| 4233 | 4229 | ||
| 4234 | return result; | 4230 | return result; |