Skip to content

Commit c2508ac

Browse files
committed
unix/mpthreadport: Use SA_SIGINFO for GC signal handler.
SA_SIGINFO allows the signal handler to access more information about the signal, especially useful in a threaded environment. The extra information is not currently used but it may prove useful in the future.
1 parent 3653f51 commit c2508ac

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

unix/mpthreadport.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,14 @@ STATIC thread_t *thread;
5656
STATIC volatile int thread_signal_done;
5757

5858
// this signal handler is used to scan the regs and stack of a thread
59-
STATIC void mp_thread_gc(int signo) {
59+
STATIC void mp_thread_gc(int signo, siginfo_t *info, void *context) {
6060
if (signo == SIGUSR1) {
6161
void gc_collect_regs_and_stack(void);
6262
gc_collect_regs_and_stack();
63+
// We have access to the context (regs, stack) of the thread but it seems
64+
// that we don't need the extra information, enough is captured by the
65+
// gc_collect_regs_and_stack function above
66+
//gc_collect_root((void**)context, sizeof(ucontext_t) / sizeof(uintptr_t));
6367
thread_signal_done = 1;
6468
}
6569
}
@@ -77,8 +81,8 @@ void mp_thread_init(void) {
7781

7882
// enable signal handler for garbage collection
7983
struct sigaction sa;
80-
sa.sa_flags = 0;
81-
sa.sa_handler = mp_thread_gc;
84+
sa.sa_flags = SA_SIGINFO;
85+
sa.sa_sigaction = mp_thread_gc;
8286
sigemptyset(&sa.sa_mask);
8387
sigaction(SIGUSR1, &sa, NULL);
8488
}

0 commit comments

Comments
 (0)