Merge branch 'fix/incorrect_critical_nesting_count_in_linux_port_v5.2' into 'release/v5.2'

fix(freertos): Fixed critical section macro in vTaskPlaceOnEventListRestricted() (v5.2)

See merge request espressif/esp-idf!32743
This commit is contained in:
Marius Vikhammer
2024-08-13 10:57:52 +08:00
6 changed files with 31 additions and 2 deletions

View File

@ -90,8 +90,13 @@ void vPortEnterCritical(void)
void vPortExitCritical(void) void vPortExitCritical(void)
{ {
/* Critical section nesting coung must never be negative */
configASSERT( port_uxCriticalNestingIDF > 0 );
if (port_uxCriticalNestingIDF > 0) { if (port_uxCriticalNestingIDF > 0) {
port_uxCriticalNestingIDF--; port_uxCriticalNestingIDF--;
if (port_uxCriticalNestingIDF == 0) { if (port_uxCriticalNestingIDF == 0) {
// Restore the saved interrupt threshold // Restore the saved interrupt threshold
vPortClearInterruptMask((int)port_uxCriticalOldInterruptStateIDF); vPortClearInterruptMask((int)port_uxCriticalOldInterruptStateIDF);

View File

@ -143,9 +143,14 @@ void vPortExitCriticalIDF(portMUX_TYPE *lock)
spinlock_release(lock); spinlock_release(lock);
BaseType_t coreID = xPortGetCoreID(); BaseType_t coreID = xPortGetCoreID();
BaseType_t nesting = port_uxCriticalNestingIDF[coreID]; BaseType_t nesting = port_uxCriticalNestingIDF[coreID];
/* Critical section nesting count must never be negative */
configASSERT( nesting > 0 );
if (nesting > 0) { if (nesting > 0) {
nesting--; nesting--;
port_uxCriticalNestingIDF[coreID] = nesting; port_uxCriticalNestingIDF[coreID] = nesting;
//This is the last exit call, restore the saved interrupt level //This is the last exit call, restore the saved interrupt level
if ( nesting == 0 ) { if ( nesting == 0 ) {
XTOS_RESTORE_JUST_INTLEVEL((int) port_uxCriticalOldInterruptStateIDF[coreID]); XTOS_RESTORE_JUST_INTLEVEL((int) port_uxCriticalOldInterruptStateIDF[coreID]);

View File

@ -261,7 +261,13 @@ void vPortEnterCritical( void )
void vPortExitCritical( void ) void vPortExitCritical( void )
{ {
uxCriticalNesting--; if ( uxCriticalNesting > 0 )
{
uxCriticalNesting--;
}
/* Critical section nesting count must always be >= 0. */
configASSERT( uxCriticalNesting >= 0 );
/* If we have reached 0 then re-enable the interrupts. */ /* If we have reached 0 then re-enable the interrupts. */
if( uxCriticalNesting == 0 ) if( uxCriticalNesting == 0 )

View File

@ -565,9 +565,13 @@ void __attribute__((optimize("-O3"))) vPortExitCriticalMultiCore(portMUX_TYPE *m
BaseType_t coreID = xPortGetCoreID(); BaseType_t coreID = xPortGetCoreID();
BaseType_t nesting = port_uxCriticalNesting[coreID]; BaseType_t nesting = port_uxCriticalNesting[coreID];
/* Critical section nesting count must never be negative */
configASSERT( nesting > 0 );
if (nesting > 0) { if (nesting > 0) {
nesting--; nesting--;
port_uxCriticalNesting[coreID] = nesting; port_uxCriticalNesting[coreID] = nesting;
//This is the last exit call, restore the saved interrupt level //This is the last exit call, restore the saved interrupt level
if ( nesting == 0 ) { if ( nesting == 0 ) {
portCLEAR_INTERRUPT_MASK_FROM_ISR(port_uxOldInterruptState[coreID]); portCLEAR_INTERRUPT_MASK_FROM_ISR(port_uxOldInterruptState[coreID]);
@ -620,8 +624,13 @@ void vPortExitCritical(void)
esp_rom_printf("vPortExitCritical(void) is not supported on single-core targets. Please use vPortExitCriticalMultiCore(portMUX_TYPE *mux) instead.\n"); esp_rom_printf("vPortExitCritical(void) is not supported on single-core targets. Please use vPortExitCriticalMultiCore(portMUX_TYPE *mux) instead.\n");
abort(); abort();
#endif /* (configNUM_CORES > 1) */ #endif /* (configNUM_CORES > 1) */
/* Critical section nesting count must never be negative */
configASSERT( port_uxCriticalNesting[0] > 0 );
if (port_uxCriticalNesting[0] > 0) { if (port_uxCriticalNesting[0] > 0) {
port_uxCriticalNesting[0]--; port_uxCriticalNesting[0]--;
if (port_uxCriticalNesting[0] == 0) { if (port_uxCriticalNesting[0] == 0) {
portCLEAR_INTERRUPT_MASK_FROM_ISR(port_uxOldInterruptState[0]); portCLEAR_INTERRUPT_MASK_FROM_ISR(port_uxOldInterruptState[0]);
} }

View File

@ -497,9 +497,13 @@ void __attribute__((optimize("-O3"))) vPortExitCritical(portMUX_TYPE *mux)
BaseType_t coreID = xPortGetCoreID(); BaseType_t coreID = xPortGetCoreID();
BaseType_t nesting = port_uxCriticalNesting[coreID]; BaseType_t nesting = port_uxCriticalNesting[coreID];
/* Critical section nesting count must never be negative */
configASSERT( nesting > 0 );
if (nesting > 0) { if (nesting > 0) {
nesting--; nesting--;
port_uxCriticalNesting[coreID] = nesting; port_uxCriticalNesting[coreID] = nesting;
//This is the last exit call, restore the saved interrupt level //This is the last exit call, restore the saved interrupt level
if ( nesting == 0 ) { if ( nesting == 0 ) {
portCLEAR_INTERRUPT_MASK_FROM_ISR(port_uxOldInterruptState[coreID]); portCLEAR_INTERRUPT_MASK_FROM_ISR(port_uxOldInterruptState[coreID]);

View File

@ -3819,7 +3819,7 @@ void vTaskPlaceOnUnorderedEventList( List_t * pxEventList,
prvAddCurrentTaskToDelayedList( xTicksToWait, xWaitIndefinitely ); prvAddCurrentTaskToDelayedList( xTicksToWait, xWaitIndefinitely );
} }
/* Release the previously taken kernel lock. */ /* Release the previously taken kernel lock. */
taskEXIT_CRITICAL( &xKernelLock ); prvEXIT_CRITICAL_SMP_ONLY( &xKernelLock );
} }
#endif /* configUSE_TIMERS */ #endif /* configUSE_TIMERS */