forked from espressif/esp-idf
Merge branch 'fix/freertos_race_cond_in_stream_buffers' into 'master'
fix(freertos): Fixed SMP race condition in stream_buffers.c Closes IDF-11376 See merge request espressif/esp-idf!34130
This commit is contained in:
@@ -123,6 +123,8 @@ The following functions were modified to accommodate SMP behavior:
|
|||||||
- In SMP, the function now disables interrupts to ensure that the calling task does not switch cores while checking its own copy of `uxSchedulerSuspended`.
|
- In SMP, the function now disables interrupts to ensure that the calling task does not switch cores while checking its own copy of `uxSchedulerSuspended`.
|
||||||
- `prvAddCurrentTaskToDelayedList()`
|
- `prvAddCurrentTaskToDelayedList()`
|
||||||
- Added extra check to see if current blocking task has already been deleted by the other core.
|
- Added extra check to see if current blocking task has already been deleted by the other core.
|
||||||
|
- `xStreamBufferReceive()`
|
||||||
|
- Added a critical section for setting `xTaskWaitingToReceive` to `NULL` so that the write is SMP safe.
|
||||||
|
|
||||||
### Critical Section Changes
|
### Critical Section Changes
|
||||||
|
|
||||||
|
@@ -6,7 +6,7 @@
|
|||||||
*
|
*
|
||||||
* SPDX-License-Identifier: MIT
|
* SPDX-License-Identifier: MIT
|
||||||
*
|
*
|
||||||
* SPDX-FileContributor: 2023 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileContributor: 2023-2024 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
* this software and associated documentation files (the "Software"), to deal in
|
* this software and associated documentation files (the "Software"), to deal in
|
||||||
@@ -977,7 +977,19 @@ size_t xStreamBufferReceive( StreamBufferHandle_t xStreamBuffer,
|
|||||||
/* Wait for data to be available. */
|
/* Wait for data to be available. */
|
||||||
traceBLOCKING_ON_STREAM_BUFFER_RECEIVE( xStreamBuffer );
|
traceBLOCKING_ON_STREAM_BUFFER_RECEIVE( xStreamBuffer );
|
||||||
( void ) xTaskNotifyWait( ( uint32_t ) 0, ( uint32_t ) 0, NULL, xTicksToWait );
|
( void ) xTaskNotifyWait( ( uint32_t ) 0, ( uint32_t ) 0, NULL, xTicksToWait );
|
||||||
pxStreamBuffer->xTaskWaitingToReceive = NULL;
|
|
||||||
|
/* In SMP mode, the task may have been woken and scheduled on
|
||||||
|
* another core. Hence, we must clear the xTaskWaitingToReceive
|
||||||
|
* handle in a critical section. */
|
||||||
|
#if ( configNUMBER_OF_CORES > 1 )
|
||||||
|
taskENTER_CRITICAL( &( pxStreamBuffer->xStreamBufferLock ) );
|
||||||
|
#endif /* configNUMBER_OF_CORES > 1 */
|
||||||
|
{
|
||||||
|
pxStreamBuffer->xTaskWaitingToReceive = NULL;
|
||||||
|
}
|
||||||
|
#if ( configNUMBER_OF_CORES > 1 )
|
||||||
|
taskEXIT_CRITICAL( &( pxStreamBuffer->xStreamBufferLock ) );
|
||||||
|
#endif /* configNUMBER_OF_CORES > 1 */
|
||||||
|
|
||||||
/* Recheck the data available after blocking. */
|
/* Recheck the data available after blocking. */
|
||||||
xBytesAvailable = prvBytesInBuffer( pxStreamBuffer );
|
xBytesAvailable = prvBytesInBuffer( pxStreamBuffer );
|
||||||
@@ -1421,7 +1433,7 @@ static void prvInitialiseNewStreamBuffer( StreamBuffer_t * const pxStreamBuffer,
|
|||||||
* result in confusion as to what is actually being observed. */
|
* result in confusion as to what is actually being observed. */
|
||||||
const BaseType_t xWriteValue = 0x55;
|
const BaseType_t xWriteValue = 0x55;
|
||||||
configASSERT( memset( pucBuffer, ( int ) xWriteValue, xBufferSizeBytes ) == pucBuffer );
|
configASSERT( memset( pucBuffer, ( int ) xWriteValue, xBufferSizeBytes ) == pucBuffer );
|
||||||
(void)xWriteValue;
|
( void ) xWriteValue;
|
||||||
} /*lint !e529 !e438 xWriteValue is only used if configASSERT() is defined. */
|
} /*lint !e529 !e438 xWriteValue is only used if configASSERT() is defined. */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user