Skip to content

Commit fc61562

Browse files
chrisncalfred2g
andauthored
Block SIG_RESUME in the main thread of the Posix port so that sigwait works as expected (#532)
Co-authored-by: alfred gedeon <[email protected]>
1 parent 4a8c066 commit fc61562

File tree

1 file changed

+9
-16
lines changed
  • portable/ThirdParty/GCC/Posix

1 file changed

+9
-16
lines changed

portable/ThirdParty/GCC/Posix/port.c

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,19 @@ portBASE_TYPE xPortStartScheduler( void )
191191
* Interrupts are disabled here already. */
192192
prvSetupTimerInterrupt();
193193

194+
/*
195+
* Block SIG_RESUME before starting any tasks so the main thread can sigwait on it.
196+
* To sigwait on an unblocked signal is undefined.
197+
* https://pubs.opengroup.org/onlinepubs/009604499/functions/sigwait.html
198+
*/
199+
sigemptyset( &xSignals );
200+
sigaddset( &xSignals, SIG_RESUME );
201+
( void ) pthread_sigmask( SIG_BLOCK, &xSignals, NULL );
202+
194203
/* Start the first task. */
195204
vPortStartFirstTask();
196205

197206
/* Wait until signaled by vPortEndScheduler(). */
198-
sigemptyset( &xSignals );
199-
sigaddset( &xSignals, SIG_RESUME );
200-
201207
while( xSchedulerEnd != pdTRUE )
202208
{
203209
sigwait( &xSignals, &iSignal );
@@ -543,23 +549,10 @@ static void prvSetupSignalsAndSchedulerPolicy( void )
543549
&xAllSignals,
544550
&xSchedulerOriginalSignalMask );
545551

546-
/* SIG_RESUME is only used with sigwait() so doesn't need a
547-
* handler. */
548-
sigresume.sa_flags = 0;
549-
sigresume.sa_handler = SIG_IGN;
550-
sigfillset( &sigresume.sa_mask );
551-
552552
sigtick.sa_flags = 0;
553553
sigtick.sa_handler = vPortSystemTickHandler;
554554
sigfillset( &sigtick.sa_mask );
555555

556-
iRet = sigaction( SIG_RESUME, &sigresume, NULL );
557-
558-
if( iRet == -1 )
559-
{
560-
prvFatalError( "sigaction", errno );
561-
}
562-
563556
iRet = sigaction( SIGALRM, &sigtick, NULL );
564557

565558
if( iRet == -1 )

0 commit comments

Comments
 (0)