- `(unwind-protect
- (without-interrupts
- (let ((*gc-inhibit* t))
- ,@body))
- ;; the test is racy, but it can err only on the overeager side
- (sb!kernel::maybe-handle-pending-gc)))
-
+ (with-unique-names (without-gcing-body)
+ `(dx-flet ((,without-gcing-body ()
+ ,@body))
+ (if *gc-inhibit*
+ (,without-gcing-body)
+ ;; We need to disable interrupts before disabling GC, so
+ ;; that signal handlers using locks don't accidentally try
+ ;; to grab them with GC inhibited.
+ (let ((*in-without-gcing* t))
+ (unwind-protect
+ (let* ((*allow-with-interrupts* nil)
+ (*interrupts-enabled* nil)
+ (*gc-inhibit* t))
+ (,without-gcing-body))
+ ;; This is not racy becuase maybe_defer_handler
+ ;; defers signals if *GC-INHIBIT* is NIL but there
+ ;; is a pending gc or stop-for-gc.
+ (when (or *interrupt-pending*
+ *gc-pending*
+ #!+sb-thread *stop-for-gc-pending*)
+ (sb!unix::receive-pending-interrupt))))))))