diff options
| author | Alan Third | 2017-01-08 09:47:51 +0000 |
|---|---|---|
| committer | Alan Third | 2017-01-08 21:29:35 +0000 |
| commit | 88a501b30d18bf1965f5416df477521ed2ca3c89 (patch) | |
| tree | 61975286df19209a9428c94d93ba9071203d2d96 /src | |
| parent | fc20bd940f41ef0784dba64c6518ddad7b63dca1 (diff) | |
| download | emacs-88a501b30d18bf1965f5416df477521ed2ca3c89.tar.gz emacs-88a501b30d18bf1965f5416df477521ed2ca3c89.zip | |
Remove apploopnr
* src/nsterm.m (ns_select, ns_read_socket): Remove apploopnr and only
allow app loop to run in main thread.
Diffstat (limited to 'src')
| -rw-r--r-- | src/nsterm.m | 113 |
1 files changed, 43 insertions, 70 deletions
diff --git a/src/nsterm.m b/src/nsterm.m index 47fc6c18acd..90664f652ff 100644 --- a/src/nsterm.m +++ b/src/nsterm.m | |||
| @@ -290,7 +290,6 @@ static int select_nfds = 0, select_valid = 0; | |||
| 290 | static struct timespec select_timeout = { 0, 0 }; | 290 | static struct timespec select_timeout = { 0, 0 }; |
| 291 | static int selfds[2] = { -1, -1 }; | 291 | static int selfds[2] = { -1, -1 }; |
| 292 | static pthread_mutex_t select_mutex; | 292 | static pthread_mutex_t select_mutex; |
| 293 | static int apploopnr = 0; | ||
| 294 | static NSAutoreleasePool *outerpool; | 293 | static NSAutoreleasePool *outerpool; |
| 295 | static struct input_event *emacs_event = NULL; | 294 | static struct input_event *emacs_event = NULL; |
| 296 | static struct input_event *q_event_ptr = NULL; | 295 | static struct input_event *q_event_ptr = NULL; |
| @@ -4011,15 +4010,6 @@ ns_check_pending_open_menu () | |||
| 4011 | } | 4010 | } |
| 4012 | #endif /* NS_IMPL_COCOA */ | 4011 | #endif /* NS_IMPL_COCOA */ |
| 4013 | 4012 | ||
| 4014 | static void | ||
| 4015 | unwind_apploopnr (Lisp_Object not_used) | ||
| 4016 | { | ||
| 4017 | --apploopnr; | ||
| 4018 | n_emacs_events_pending = 0; | ||
| 4019 | ns_finish_events (); | ||
| 4020 | q_event_ptr = NULL; | ||
| 4021 | } | ||
| 4022 | |||
| 4023 | static int | 4013 | static int |
| 4024 | ns_read_socket (struct terminal *terminal, struct input_event *hold_quit) | 4014 | ns_read_socket (struct terminal *terminal, struct input_event *hold_quit) |
| 4025 | /* -------------------------------------------------------------------------- | 4015 | /* -------------------------------------------------------------------------- |
| @@ -4033,9 +4023,6 @@ ns_read_socket (struct terminal *terminal, struct input_event *hold_quit) | |||
| 4033 | 4023 | ||
| 4034 | NSTRACE_WHEN (NSTRACE_GROUP_EVENTS, "ns_read_socket"); | 4024 | NSTRACE_WHEN (NSTRACE_GROUP_EVENTS, "ns_read_socket"); |
| 4035 | 4025 | ||
| 4036 | if (apploopnr > 0) | ||
| 4037 | return -1; /* Already within event loop. */ | ||
| 4038 | |||
| 4039 | #ifdef HAVE_NATIVE_FS | 4026 | #ifdef HAVE_NATIVE_FS |
| 4040 | check_native_fs (); | 4027 | check_native_fs (); |
| 4041 | #endif | 4028 | #endif |
| @@ -4052,54 +4039,51 @@ ns_read_socket (struct terminal *terminal, struct input_event *hold_quit) | |||
| 4052 | return i; | 4039 | return i; |
| 4053 | } | 4040 | } |
| 4054 | 4041 | ||
| 4055 | block_input (); | 4042 | if ([NSThread mainThread]) |
| 4056 | n_emacs_events_pending = 0; | ||
| 4057 | ns_init_events (&ev); | ||
| 4058 | q_event_ptr = hold_quit; | ||
| 4059 | |||
| 4060 | /* we manage autorelease pools by allocate/reallocate each time around | ||
| 4061 | the loop; strict nesting is occasionally violated but seems not to | ||
| 4062 | matter.. earlier methods using full nesting caused major memory leaks */ | ||
| 4063 | [outerpool release]; | ||
| 4064 | outerpool = [[NSAutoreleasePool alloc] init]; | ||
| 4065 | |||
| 4066 | /* If have pending open-file requests, attend to the next one of those. */ | ||
| 4067 | if (ns_pending_files && [ns_pending_files count] != 0 | ||
| 4068 | && [(EmacsApp *)NSApp openFile: [ns_pending_files objectAtIndex: 0]]) | ||
| 4069 | { | ||
| 4070 | [ns_pending_files removeObjectAtIndex: 0]; | ||
| 4071 | } | ||
| 4072 | /* Deal with pending service requests. */ | ||
| 4073 | else if (ns_pending_service_names && [ns_pending_service_names count] != 0 | ||
| 4074 | && [(EmacsApp *) | ||
| 4075 | NSApp fulfillService: [ns_pending_service_names objectAtIndex: 0] | ||
| 4076 | withArg: [ns_pending_service_args objectAtIndex: 0]]) | ||
| 4077 | { | ||
| 4078 | [ns_pending_service_names removeObjectAtIndex: 0]; | ||
| 4079 | [ns_pending_service_args removeObjectAtIndex: 0]; | ||
| 4080 | } | ||
| 4081 | else | ||
| 4082 | { | 4043 | { |
| 4083 | ptrdiff_t specpdl_count = SPECPDL_INDEX (); | 4044 | block_input (); |
| 4084 | /* Run and wait for events. We must always send one NX_APPDEFINED event | 4045 | n_emacs_events_pending = 0; |
| 4085 | to ourself, otherwise [NXApp run] will never exit. */ | 4046 | ns_init_events (&ev); |
| 4086 | send_appdefined = YES; | 4047 | q_event_ptr = hold_quit; |
| 4087 | ns_send_appdefined (-1); | 4048 | |
| 4088 | 4049 | /* we manage autorelease pools by allocate/reallocate each time around | |
| 4089 | if (++apploopnr != 1) | 4050 | the loop; strict nesting is occasionally violated but seems not to |
| 4051 | matter.. earlier methods using full nesting caused major memory leaks */ | ||
| 4052 | [outerpool release]; | ||
| 4053 | outerpool = [[NSAutoreleasePool alloc] init]; | ||
| 4054 | |||
| 4055 | /* If have pending open-file requests, attend to the next one of those. */ | ||
| 4056 | if (ns_pending_files && [ns_pending_files count] != 0 | ||
| 4057 | && [(EmacsApp *)NSApp openFile: [ns_pending_files objectAtIndex: 0]]) | ||
| 4090 | { | 4058 | { |
| 4091 | emacs_abort (); | 4059 | [ns_pending_files removeObjectAtIndex: 0]; |
| 4092 | } | 4060 | } |
| 4093 | record_unwind_protect (unwind_apploopnr, Qt); | 4061 | /* Deal with pending service requests. */ |
| 4094 | [NSApp run]; | 4062 | else if (ns_pending_service_names && [ns_pending_service_names count] != 0 |
| 4095 | unbind_to (specpdl_count, Qnil); /* calls unwind_apploopnr */ | 4063 | && [(EmacsApp *) |
| 4096 | } | 4064 | NSApp fulfillService: [ns_pending_service_names objectAtIndex: 0] |
| 4065 | withArg: [ns_pending_service_args objectAtIndex: 0]]) | ||
| 4066 | { | ||
| 4067 | [ns_pending_service_names removeObjectAtIndex: 0]; | ||
| 4068 | [ns_pending_service_args removeObjectAtIndex: 0]; | ||
| 4069 | } | ||
| 4070 | else | ||
| 4071 | { | ||
| 4072 | ptrdiff_t specpdl_count = SPECPDL_INDEX (); | ||
| 4073 | /* Run and wait for events. We must always send one NX_APPDEFINED event | ||
| 4074 | to ourself, otherwise [NXApp run] will never exit. */ | ||
| 4075 | send_appdefined = YES; | ||
| 4076 | ns_send_appdefined (-1); | ||
| 4097 | 4077 | ||
| 4098 | nevents = n_emacs_events_pending; | 4078 | [NSApp run]; |
| 4099 | n_emacs_events_pending = 0; | 4079 | } |
| 4100 | ns_finish_events (); | 4080 | |
| 4101 | q_event_ptr = NULL; | 4081 | nevents = n_emacs_events_pending; |
| 4102 | unblock_input (); | 4082 | n_emacs_events_pending = 0; |
| 4083 | ns_finish_events (); | ||
| 4084 | q_event_ptr = NULL; | ||
| 4085 | unblock_input (); | ||
| 4086 | } | ||
| 4103 | 4087 | ||
| 4104 | return nevents; | 4088 | return nevents; |
| 4105 | } | 4089 | } |
| @@ -4120,9 +4104,6 @@ ns_select (int nfds, fd_set *readfds, fd_set *writefds, | |||
| 4120 | 4104 | ||
| 4121 | NSTRACE_WHEN (NSTRACE_GROUP_EVENTS, "ns_select"); | 4105 | NSTRACE_WHEN (NSTRACE_GROUP_EVENTS, "ns_select"); |
| 4122 | 4106 | ||
| 4123 | if (apploopnr > 0) | ||
| 4124 | return -1; /* Already within event loop. */ | ||
| 4125 | |||
| 4126 | #ifdef HAVE_NATIVE_FS | 4107 | #ifdef HAVE_NATIVE_FS |
| 4127 | check_native_fs (); | 4108 | check_native_fs (); |
| 4128 | #endif | 4109 | #endif |
| @@ -4142,6 +4123,7 @@ ns_select (int nfds, fd_set *readfds, fd_set *writefds, | |||
| 4142 | } | 4123 | } |
| 4143 | 4124 | ||
| 4144 | if (NSApp == nil | 4125 | if (NSApp == nil |
| 4126 | || ![NSThread mainThread] | ||
| 4145 | || (timeout && timeout->tv_sec == 0 && timeout->tv_nsec == 0)) | 4127 | || (timeout && timeout->tv_sec == 0 && timeout->tv_nsec == 0)) |
| 4146 | return pselect (nfds, readfds, writefds, exceptfds, timeout, sigmask); | 4128 | return pselect (nfds, readfds, writefds, exceptfds, timeout, sigmask); |
| 4147 | 4129 | ||
| @@ -4198,17 +4180,8 @@ ns_select (int nfds, fd_set *readfds, fd_set *writefds, | |||
| 4198 | 4180 | ||
| 4199 | block_input (); | 4181 | block_input (); |
| 4200 | ns_init_events (&event); | 4182 | ns_init_events (&event); |
| 4201 | if (++apploopnr != 1) | ||
| 4202 | { | ||
| 4203 | emacs_abort (); | ||
| 4204 | } | ||
| 4205 | 4183 | ||
| 4206 | { | 4184 | [NSApp run]; |
| 4207 | ptrdiff_t specpdl_count = SPECPDL_INDEX (); | ||
| 4208 | record_unwind_protect (unwind_apploopnr, Qt); | ||
| 4209 | [NSApp run]; | ||
| 4210 | unbind_to (specpdl_count, Qnil); /* calls unwind_apploopnr */ | ||
| 4211 | } | ||
| 4212 | 4185 | ||
| 4213 | ns_finish_events (); | 4186 | ns_finish_events (); |
| 4214 | if (nr > 0 && readfds) | 4187 | if (nr > 0 && readfds) |