From 2fcb0ad63fd65991c5ef322635ff38bcd6b81eaf Mon Sep 17 00:00:00 2001 From: John Boiles Date: Fri, 17 Jan 2025 16:48:44 -0800 Subject: [PATCH] Clear SIGRESUME (SIGUSR1) when exiting xPortStartScheduler --- portable/ThirdParty/GCC/Posix/port.c | 30 ++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/portable/ThirdParty/GCC/Posix/port.c b/portable/ThirdParty/GCC/Posix/port.c index 1bec7afd8..0209218ee 100644 --- a/portable/ThirdParty/GCC/Posix/port.c +++ b/portable/ThirdParty/GCC/Posix/port.c @@ -202,6 +202,33 @@ void vPortStartFirstTask( void ) } /*-----------------------------------------------------------*/ +/* + * Clear a signal that is pending for the calling thread. + */ +void prvClearPendingSignal( int sig ) +{ + sigset_t set, oldset; + + /* Block the signal */ + sigemptyset( &set ); + sigaddset( &set, sig ); + pthread_sigmask( SIG_BLOCK, &set, &oldset ); + + /* Check if signal is pending */ + sigpending( &set ); + + if( sigismember( &set, sig ) ) + { + int signum; + /* Wait for and remove signal */ + sigwait( &set, &signum ); + } + + /* Restore the original signal mask */ + pthread_sigmask( SIG_SETMASK, &oldset, NULL ); +} +/*-----------------------------------------------------------*/ + /* * See header file for description. */ @@ -250,6 +277,9 @@ BaseType_t xPortStartScheduler( void ) hSigSetupThread = PTHREAD_ONCE_INIT; #endif /* __APPLE__*/ + // Clear SIG_RESUME (SIGUSR1), because it might have fired again while we were shutting things down. + prvClearPendingSignal( SIG_RESUME ); + /* Restore original signal mask. */ ( void ) pthread_sigmask( SIG_SETMASK, &xSchedulerOriginalSignalMask, NULL );