smp branch: bugfix for race condition on RP2040 (#431)

* Bugfix for race condition on RP2040 in vPortEnableInterrupts()

RP2040 SMP port: Since spin_unlock() re-enables interrupts, pxYieldSpinLock has to be updated first to avoid a possible race condition.

* Bugfix for invalid sanity checks on RP2040

RP2040 SMP port: Testing pxYieldSpinLock for NULL does not work reliable in these places, because another/new lock might already be set when configASSERT() is executed.
This commit is contained in:
Timo Sandmann 2021-12-28 21:30:03 +01:00 committed by GitHub
parent 7d11089624
commit 4832377117
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -375,8 +375,9 @@ void vPortEnableInterrupts( void )
#if ( configSUPPORT_PICO_SYNC_INTEROP == 1 ) #if ( configSUPPORT_PICO_SYNC_INTEROP == 1 )
if( pxYieldSpinLock ) if( pxYieldSpinLock )
{ {
spin_unlock(pxYieldSpinLock, ulYieldSpinLockSaveValue); spin_lock_t* const pxTmpLock = pxYieldSpinLock;
pxYieldSpinLock = NULL; pxYieldSpinLock = NULL;
spin_unlock( pxTmpLock, ulYieldSpinLockSaveValue );
} }
#endif #endif
__asm volatile ( " cpsie i " ::: "memory" ); __asm volatile ( " cpsie i " ::: "memory" );
@ -782,9 +783,6 @@ __attribute__( ( weak ) ) void vPortSetupTimerInterrupt( void )
ulYieldSpinLockSaveValue = ulSave; ulYieldSpinLockSaveValue = ulSave;
xEventGroupWaitBits( xEventGroup, prvGetEventGroupBit(pxLock->spin_lock), xEventGroupWaitBits( xEventGroup, prvGetEventGroupBit(pxLock->spin_lock),
pdTRUE, pdFALSE, portMAX_DELAY); pdTRUE, pdFALSE, portMAX_DELAY);
/* sanity check that interrupts were disabled, then re-enabled during the call, which will have
* taken care of the yield */
configASSERT( pxYieldSpinLock == NULL);
} }
} }
@ -857,9 +855,6 @@ __attribute__( ( weak ) ) void vPortSetupTimerInterrupt( void )
xEventGroupWaitBits( xEventGroup, xEventGroupWaitBits( xEventGroup,
prvGetEventGroupBit(pxLock->spin_lock), pdTRUE, prvGetEventGroupBit(pxLock->spin_lock), pdTRUE,
pdFALSE, uxTicksToWait ); pdFALSE, uxTicksToWait );
/* sanity check that interrupts were disabled, then re-enabled during the call, which will have
* taken care of the yield */
configASSERT( pxYieldSpinLock == NULL );
} }
else else
{ {