From 938131f3315202a92005aa661ea01507405376a7 Mon Sep 17 00:00:00 2001 From: Guilherme Affonso Date: Thu, 10 Nov 2022 18:20:04 +0900 Subject: [PATCH] Don't resume previously suspended threads on gc --- lisp/c/eus_proto.h | 1 + lisp/c/eus_thr.h | 1 + lisp/c/memory.c | 4 +- lisp/c/mthread_posix.c | 115 +++++++++++++++++++---------------------- 4 files changed, 57 insertions(+), 64 deletions(-) diff --git a/lisp/c/eus_proto.h b/lisp/c/eus_proto.h index be8b5a8d9..183085e13 100644 --- a/lisp/c/eus_proto.h +++ b/lisp/c/eus_proto.h @@ -500,6 +500,7 @@ extern int thr_setprio(int /*tid*/, int /*prio*/); extern int thr_create(void */*base*/, size_t /*size*/, void (*/*func*/)(), void */*args*/, long /*flags*/, int */*tid*/); extern int thr_continue(int /*tid*/); extern int thr_suspend(int /*tid*/); +extern int thr_unsuspend(int /*tid*/); extern int thr_kill(int /*tid*/, int /*sig*/); extern int thr_cancel(int /*tid*/); extern int thr_join(int /*tid*/, int */*depature*/, void **/*status*/); diff --git a/lisp/c/eus_thr.h b/lisp/c/eus_thr.h index a64ea0699..70e1e5157 100644 --- a/lisp/c/eus_thr.h +++ b/lisp/c/eus_thr.h @@ -113,6 +113,7 @@ extern int thr_create(void *, size_t, void (*)(), void *, long, int *); extern int thr_setprio(int, int); extern int thr_continue(int); extern int thr_suspend(int); +extern int thr_unsuspend(int); extern int thr_kill(int, int); extern int thr_cancel(int); diff --git a/lisp/c/memory.c b/lisp/c/memory.c index e52dfd4ab..447e5cb35 100644 --- a/lisp/c/memory.c +++ b/lisp/c/memory.c @@ -762,7 +762,9 @@ void resume_all_threads() self=thr_self(); for (i=0; i1) { + susp_sentinel = 1; + return; + } + + /* + * Block all signals except SIGUSR1 and SIGUSR2 while suspended. */ sigfillset (&signal_set); + sigdelset (&signal_set, SIGUSR1); sigdelset (&signal_set, SIGUSR2); susp_sentinel = 1; - sigsuspend (&signal_set); + while(susp_count[thr_self()]>0) { + sigsuspend (&signal_set); + } /* * Once I'm here, I've been resumed, and the resume signal @@ -158,6 +169,7 @@ suspend_signal_handler (int sig) void resume_signal_handler (int sig) { + susp_count[thr_self()] -= 1; return; } @@ -168,15 +180,15 @@ resume_signal_handler (int sig) void suspend_init_routine (void) { - int status; + int i, status; struct sigaction sigusr1, sigusr2; /* - * Allocate the suspended threads array. This array is used - * to guarentee idempotency + * Initialize suspension counter */ - //susp_bottom = 10; -// susp_array = (pthread_t*) calloc (susp_bottom, sizeof (pthread_t)); + for (i=0; i= susp_bottom) { - pthread_mutex_unlock (&susp_mut); - return 0; - } - /* * Signal the thread to continue, and remove the thread from * the suspended array. @@ -335,10 +300,34 @@ pthread_continue (pthread_t target_thread) return status; } - susp_array[i] = 0; /* Clear array element */ status = pthread_mutex_unlock (&susp_mut); return status; } + +/* + * Ensures that a suspended thread is resumed, even if + * multiple suspension requests have been received. + */ +int +//thr_continue (pthread_t target_thread) +pthread_continue (pthread_t target_thread) +{ + int i; + for(i = 0; i < MAXTHREAD && !pthread_equal(thread_table[i].tid,target_thread); i++); + if (i == MAXTHREAD) return(-1); + + susp_count[i] = 1; + return pthread_unsuspend(target_thread); +} + +int thr_unsuspend( int tid ) { + return pthread_unsuspend( thread_table[tid].tid ); +} +#else +int thr_unsuspend( int tid ) { + // not supported, always continue + return pthread_continue ( thread_table[tid].tid ); +} #endif int thr_suspend( int tid ) { return pthread_suspend ( thread_table[tid].tid );