summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Third <alan@idiocy.org>2017-01-08 09:47:51 +0000
committerAlan Third <alan@idiocy.org>2017-01-08 21:29:35 +0000
commit88a501b30d18bf1965f5416df477521ed2ca3c89 (patch)
tree61975286df19209a9428c94d93ba9071203d2d96
parentfc20bd940f41ef0784dba64c6518ddad7b63dca1 (diff)
downloademacs-88a501b30d18bf1965f5416df477521ed2ca3c89.tar.gz
Remove apploopnr
* src/nsterm.m (ns_select, ns_read_socket): Remove apploopnr and only allow app loop to run in main thread.
-rw-r--r--src/nsterm.m113
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;
static struct timespec select_timeout = { 0, 0 };
static int selfds[2] = { -1, -1 };
static pthread_mutex_t select_mutex;
-static int apploopnr = 0;
static NSAutoreleasePool *outerpool;
static struct input_event *emacs_event = NULL;
static struct input_event *q_event_ptr = NULL;
@@ -4011,15 +4010,6 @@ ns_check_pending_open_menu ()
}
#endif /* NS_IMPL_COCOA */
-static void
-unwind_apploopnr (Lisp_Object not_used)
-{
- --apploopnr;
- n_emacs_events_pending = 0;
- ns_finish_events ();
- q_event_ptr = NULL;
-}
-
static int
ns_read_socket (struct terminal *terminal, struct input_event *hold_quit)
/* --------------------------------------------------------------------------
@@ -4033,9 +4023,6 @@ ns_read_socket (struct terminal *terminal, struct input_event *hold_quit)
NSTRACE_WHEN (NSTRACE_GROUP_EVENTS, "ns_read_socket");
- if (apploopnr > 0)
- return -1; /* Already within event loop. */
-
#ifdef HAVE_NATIVE_FS
check_native_fs ();
#endif
@@ -4052,54 +4039,51 @@ ns_read_socket (struct terminal *terminal, struct input_event *hold_quit)
return i;
}
- block_input ();
- n_emacs_events_pending = 0;
- ns_init_events (&ev);
- q_event_ptr = hold_quit;
-
- /* we manage autorelease pools by allocate/reallocate each time around
- the loop; strict nesting is occasionally violated but seems not to
- matter.. earlier methods using full nesting caused major memory leaks */
- [outerpool release];
- outerpool = [[NSAutoreleasePool alloc] init];
-
- /* If have pending open-file requests, attend to the next one of those. */
- if (ns_pending_files && [ns_pending_files count] != 0
- && [(EmacsApp *)NSApp openFile: [ns_pending_files objectAtIndex: 0]])
- {
- [ns_pending_files removeObjectAtIndex: 0];
- }
- /* Deal with pending service requests. */
- else if (ns_pending_service_names && [ns_pending_service_names count] != 0
- && [(EmacsApp *)
- NSApp fulfillService: [ns_pending_service_names objectAtIndex: 0]
- withArg: [ns_pending_service_args objectAtIndex: 0]])
- {
- [ns_pending_service_names removeObjectAtIndex: 0];
- [ns_pending_service_args removeObjectAtIndex: 0];
- }
- else
+ if ([NSThread mainThread])
{
- ptrdiff_t specpdl_count = SPECPDL_INDEX ();
- /* Run and wait for events. We must always send one NX_APPDEFINED event
- to ourself, otherwise [NXApp run] will never exit. */
- send_appdefined = YES;
- ns_send_appdefined (-1);
-
- if (++apploopnr != 1)
+ block_input ();
+ n_emacs_events_pending = 0;
+ ns_init_events (&ev);
+ q_event_ptr = hold_quit;
+
+ /* we manage autorelease pools by allocate/reallocate each time around
+ the loop; strict nesting is occasionally violated but seems not to
+ matter.. earlier methods using full nesting caused major memory leaks */
+ [outerpool release];
+ outerpool = [[NSAutoreleasePool alloc] init];
+
+ /* If have pending open-file requests, attend to the next one of those. */
+ if (ns_pending_files && [ns_pending_files count] != 0
+ && [(EmacsApp *)NSApp openFile: [ns_pending_files objectAtIndex: 0]])
{
- emacs_abort ();
+ [ns_pending_files removeObjectAtIndex: 0];
}
- record_unwind_protect (unwind_apploopnr, Qt);
- [NSApp run];
- unbind_to (specpdl_count, Qnil); /* calls unwind_apploopnr */
- }
+ /* Deal with pending service requests. */
+ else if (ns_pending_service_names && [ns_pending_service_names count] != 0
+ && [(EmacsApp *)
+ NSApp fulfillService: [ns_pending_service_names objectAtIndex: 0]
+ withArg: [ns_pending_service_args objectAtIndex: 0]])
+ {
+ [ns_pending_service_names removeObjectAtIndex: 0];
+ [ns_pending_service_args removeObjectAtIndex: 0];
+ }
+ else
+ {
+ ptrdiff_t specpdl_count = SPECPDL_INDEX ();
+ /* Run and wait for events. We must always send one NX_APPDEFINED event
+ to ourself, otherwise [NXApp run] will never exit. */
+ send_appdefined = YES;
+ ns_send_appdefined (-1);
- nevents = n_emacs_events_pending;
- n_emacs_events_pending = 0;
- ns_finish_events ();
- q_event_ptr = NULL;
- unblock_input ();
+ [NSApp run];
+ }
+
+ nevents = n_emacs_events_pending;
+ n_emacs_events_pending = 0;
+ ns_finish_events ();
+ q_event_ptr = NULL;
+ unblock_input ();
+ }
return nevents;
}
@@ -4120,9 +4104,6 @@ ns_select (int nfds, fd_set *readfds, fd_set *writefds,
NSTRACE_WHEN (NSTRACE_GROUP_EVENTS, "ns_select");
- if (apploopnr > 0)
- return -1; /* Already within event loop. */
-
#ifdef HAVE_NATIVE_FS
check_native_fs ();
#endif
@@ -4142,6 +4123,7 @@ ns_select (int nfds, fd_set *readfds, fd_set *writefds,
}
if (NSApp == nil
+ || ![NSThread mainThread]
|| (timeout && timeout->tv_sec == 0 && timeout->tv_nsec == 0))
return pselect (nfds, readfds, writefds, exceptfds, timeout, sigmask);
@@ -4198,17 +4180,8 @@ ns_select (int nfds, fd_set *readfds, fd_set *writefds,
block_input ();
ns_init_events (&event);
- if (++apploopnr != 1)
- {
- emacs_abort ();
- }
- {
- ptrdiff_t specpdl_count = SPECPDL_INDEX ();
- record_unwind_protect (unwind_apploopnr, Qt);
- [NSApp run];
- unbind_to (specpdl_count, Qnil); /* calls unwind_apploopnr */
- }
+ [NSApp run];
ns_finish_events ();
if (nr > 0 && readfds)