Skip to content

Commit

Permalink
Block SIG_RESUME in the main thread of the Posix port so that sigwait…
Browse files Browse the repository at this point in the history
… works as expected (FreeRTOS#532)

Co-authored-by: alfred gedeon <28123637+alfred2g@users.noreply.github.com>
  • Loading branch information
chrisnc and alfred2g authored Aug 4, 2022
1 parent 4a8c066 commit fc61562
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions portable/ThirdParty/GCC/Posix/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,19 @@ portBASE_TYPE xPortStartScheduler( void )
* Interrupts are disabled here already. */
prvSetupTimerInterrupt();

/*
* Block SIG_RESUME before starting any tasks so the main thread can sigwait on it.
* To sigwait on an unblocked signal is undefined.
* https://pubs.opengroup.org/onlinepubs/009604499/functions/sigwait.html
*/
sigemptyset( &xSignals );
sigaddset( &xSignals, SIG_RESUME );
( void ) pthread_sigmask( SIG_BLOCK, &xSignals, NULL );

/* Start the first task. */
vPortStartFirstTask();

/* Wait until signaled by vPortEndScheduler(). */
sigemptyset( &xSignals );
sigaddset( &xSignals, SIG_RESUME );

while( xSchedulerEnd != pdTRUE )
{
sigwait( &xSignals, &iSignal );
Expand Down Expand Up @@ -543,23 +549,10 @@ static void prvSetupSignalsAndSchedulerPolicy( void )
&xAllSignals,
&xSchedulerOriginalSignalMask );

/* SIG_RESUME is only used with sigwait() so doesn't need a
* handler. */
sigresume.sa_flags = 0;
sigresume.sa_handler = SIG_IGN;
sigfillset( &sigresume.sa_mask );

sigtick.sa_flags = 0;
sigtick.sa_handler = vPortSystemTickHandler;
sigfillset( &sigtick.sa_mask );

iRet = sigaction( SIG_RESUME, &sigresume, NULL );

if( iRet == -1 )
{
prvFatalError( "sigaction", errno );
}

iRet = sigaction( SIGALRM, &sigtick, NULL );

if( iRet == -1 )
Expand Down

0 comments on commit fc61562

Please sign in to comment.