>From b11813832663e46ac3d55fa31a7980fd69bf98a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20F=2E=20Wittenberger?= Date: Wed, 2 Dec 2015 13:25:58 +0100 Subject: [PATCH] allow signal handlers to be called from any thread --- runtime.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/runtime.c b/runtime.c index 9d93476..2d670bb 100644 --- a/runtime.c +++ b/runtime.c @@ -4394,21 +4394,20 @@ C_regparm void C_fcall C_paranoid_check_for_interrupt(void) C_regparm void C_fcall C_raise_interrupt(int reason) { + int c; if(C_interrupts_enabled) { - if(pending_interrupts_count == 0 && !handling_interrupts) { + /* Immediatedly increment pending_interrupts_count to ensure + signals dispatched in C_cpu_milliseconds take the alternative path.*/ + c = pending_interrupts_count++; + if(c == 0 && !handling_interrupts) { + pending_interrupts[0] = reason; /* Force the next stack check to fail by faking a "full" stack. That causes save_and_reclaim() to be called, which will invoke handle_interrupt() (which restores the stack limit). */ saved_stack_limit = C_stack_limit; - -#if C_STACK_GROWS_DOWNWARD - C_stack_limit = C_stack_pointer + 1000; -#else - C_stack_limit = C_stack_pointer - 1000; -#endif + C_stack_limit = stack_bottom; interrupt_time = C_cpu_milliseconds(); - pending_interrupts[ pending_interrupts_count++ ] = reason; - } else if(pending_interrupts_count < MAX_PENDING_INTERRUPTS) { + } else if(c < MAX_PENDING_INTERRUPTS) { int i; /* * Drop signals if too many, but don't queue up multiple entries @@ -4418,8 +4417,7 @@ C_regparm void C_fcall C_raise_interrupt(int reason) if (pending_interrupts[i] == reason) return; } - pending_interrupts[ pending_interrupts_count++ ] = reason; + pending_interrupts[ c ] = reason; } else { pending_interrupts_count = MAX_PENDING_INTERRUPTS; } } } -- 2.6.2