+#ifdef LISP_FEATURE_SB_THREAD
+/* When trying to get all_threads_lock one should make sure that
+ * sig_stop_for_gc is not blocked. Else there would be a possible
+ * deadlock: gc locks it, other thread blocks signals, gc sends stop
+ * request to other thread and waits, other thread blocks on lock. */
+void check_sig_stop_for_gc_can_arrive_or_lose()
+{
+ /* Get the current sigmask, by blocking the empty set. */
+ sigset_t empty,current;
+ sigemptyset(&empty);
+ thread_sigmask(SIG_BLOCK, &empty, ¤t);
+ if (sigismember(¤t,SIG_STOP_FOR_GC))
+ lose("SIG_STOP_FOR_GC is blocked\n");
+ if (SymbolValue(INTERRUPTS_ENABLED,arch_os_get_current_thread()) == NIL)
+ lose("interrupts disabled\n");
+ if (arch_pseudo_atomic_atomic(NULL))
+ lose("n pseudo atomic\n");
+}
+
+#ifdef QSHOW_SIGNALS
+#define FSHOW_SIGNAL FSHOW
+#else
+#define FSHOW_SIGNAL(args)
+#endif
+
+#define GET_ALL_THREADS_LOCK(name) \
+ { \
+ sigset_t _newset,_oldset; \
+ sigemptyset(&_newset); \
+ sigaddset_blockable(&_newset); \
+ sigdelset(&_newset,SIG_STOP_FOR_GC); \
+ thread_sigmask(SIG_BLOCK, &_newset, &_oldset); \
+ check_sig_stop_for_gc_can_arrive_or_lose(); \
+ FSHOW_SIGNAL((stderr,"/%s:waiting on lock=%ld, thread=%ld\n",name, \
+ all_threads_lock,arch_os_get_current_thread()->os_thread)); \
+ get_spinlock(&all_threads_lock,(long)arch_os_get_current_thread()); \
+ FSHOW_SIGNAL((stderr,"/%s:got lock, thread=%ld\n", \
+ name,arch_os_get_current_thread()->os_thread));
+
+#define RELEASE_ALL_THREADS_LOCK(name) \
+ FSHOW_SIGNAL((stderr,"/%s:released lock\n",name)); \
+ release_spinlock(&all_threads_lock); \
+ thread_sigmask(SIG_SETMASK,&_oldset,0); \
+ }
+#endif
+