Skip to content

Commit

Permalink
Simpler, more targeted solution
Browse files Browse the repository at this point in the history
  • Loading branch information
johnboiles committed Jan 29, 2025
1 parent 0e644d3 commit 94263d2
Showing 1 changed file with 11 additions and 31 deletions.
42 changes: 11 additions & 31 deletions portable/ThirdParty/GCC/Posix/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,39 +260,12 @@ 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.
*/
BaseType_t xPortStartScheduler( void )
{
int iSignal;
int iSignal = 0;
sigset_t xSignals;

hMainThread = pthread_self();
Expand All @@ -318,6 +291,16 @@ BaseType_t xPortStartScheduler( void )
while( xSchedulerEnd != pdTRUE )
{
sigwait( &xSignals, &iSignal );

/* For some reason, sigwait() doesn't always clear the signal the first time.
* Clear it again if it's still pending.
*/
sigset_t set;
sigpending( &set );
if( sigismember( &set, SIG_RESUME ) )
{
sigwait( &xSignals, &iSignal );
}
}

/*
Expand All @@ -335,9 +318,6 @@ 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 );

Expand Down

0 comments on commit 94263d2

Please sign in to comment.