+ if (SymbolValue(GC_INHIBIT,thread)==NIL) {
+ void *original_pending_handler = data->pending_handler;
+
+#ifdef LISP_FEATURE_SB_THREAD
+ if (SymbolValue(STOP_FOR_GC_PENDING,thread) != NIL) {
+ /* STOP_FOR_GC_PENDING and GC_PENDING are cleared by
+ * the signal handler if it actually stops us. */
+ arch_clear_pseudo_atomic_interrupted(context);
+ sig_stop_for_gc_handler(SIG_STOP_FOR_GC,NULL,context);
+ } else
+#endif
+ /* Test for T and not for != NIL since the value :IN-PROGRESS
+ * is used in SUB-GC as part of the mechanism to supress
+ * recursive gcs.*/
+ if (SymbolValue(GC_PENDING,thread) == T) {
+
+ /* Two reasons for doing this. First, if there is a
+ * pending handler we don't want to run. Second, we are
+ * going to clear pseudo atomic interrupted to avoid
+ * spurious trapping on every allocation in SUB_GC and
+ * having a pending handler with interrupts enabled and
+ * without pseudo atomic interrupted breaks an
+ * invariant. */
+ if (data->pending_handler) {
+ bind_variable(ALLOW_WITH_INTERRUPTS, NIL, thread);
+ bind_variable(INTERRUPTS_ENABLED, NIL, thread);
+ }
+
+ arch_clear_pseudo_atomic_interrupted(context);
+
+ /* GC_PENDING is cleared in SUB-GC, or if another thread
+ * is doing a gc already we will get a SIG_STOP_FOR_GC and
+ * that will clear it.
+ *
+ * If there is a pending handler or gc was triggerred in a
+ * signal handler then maybe_gc won't run POST_GC and will
+ * return normally. */
+ if (!maybe_gc(context))
+ lose("GC not inhibited but maybe_gc did not GC.");
+
+ if (data->pending_handler) {
+ unbind(thread);
+ unbind(thread);
+ }
+ } else if (SymbolValue(GC_PENDING,thread) != NIL) {
+ /* It's not NIL or T so GC_PENDING is :IN-PROGRESS. If
+ * GC-PENDING is not NIL then we cannot trap on pseudo
+ * atomic due to GC (see if(GC_PENDING) logic in
+ * cheneygc.c an gengcgc.c), plus there is a outer
+ * WITHOUT-INTERRUPTS SUB_GC, so how did we end up
+ * here? */
+ lose("Trapping to run pending handler while GC in progress.");
+ }
+
+ check_blockables_blocked_or_lose(0);
+
+ /* No GC shall be lost. If SUB_GC triggers another GC then
+ * that should be handled on the spot. */
+ if (SymbolValue(GC_PENDING,thread) != NIL)
+ lose("GC_PENDING after doing gc.");
+#ifdef LISP_FEATURE_SB_THREAD
+ if (SymbolValue(STOP_FOR_GC_PENDING,thread) != NIL)
+ lose("STOP_FOR_GC_PENDING after doing gc.");
+#endif
+ /* Check two things. First, that gc does not clobber a handler
+ * that's already pending. Second, that there is no interrupt
+ * lossage: if original_pending_handler was NULL then even if
+ * an interrupt arrived during GC (POST-GC, really) it was
+ * handled. */
+ if (original_pending_handler != data->pending_handler)
+ lose("pending handler changed in gc: %x -> %d.",
+ original_pending_handler, data->pending_handler);
+ }
+
+#ifndef LISP_FEATURE_WIN32
+ /* There may be no pending handler, because it was only a gc that
+ * had to be executed or because Lisp is a bit too eager to call
+ * DO-PENDING-INTERRUPT. */
+ if ((SymbolValue(INTERRUPTS_ENABLED,thread) != NIL) &&
+ (data->pending_handler)) {
+ /* No matter how we ended up here, clear both
+ * INTERRUPT_PENDING and pseudo atomic interrupted. It's safe
+ * because we checked above that there is no GC pending. */
+ SetSymbolValue(INTERRUPT_PENDING, NIL, thread);
+ arch_clear_pseudo_atomic_interrupted(context);
+ /* Restore the sigmask in the context. */
+ sigcopyset(os_context_sigmask_addr(context), &data->pending_mask);
+ run_deferred_handler(data, context);