Skip to content

Commit 4ee7179

Browse files
fix(freertos-smp): Stream Buffer task lists must be manipulated in critical sections
Stream buffer task lists (xTaskWaitingToSend and xTaskWaitingToReceive) are updated without critical sections. These objects are shared objects and can be updated from an ISR context as well. Hence, these lists must always be updated in critical sections.
1 parent a1cc3bd commit 4ee7179

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

stream_buffer.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,11 @@ size_t xStreamBufferSend( StreamBufferHandle_t xStreamBuffer,
947947

948948
traceBLOCKING_ON_STREAM_BUFFER_SEND( xStreamBuffer );
949949
( void ) xTaskNotifyWaitIndexed( pxStreamBuffer->uxNotificationIndex, ( uint32_t ) 0, ( uint32_t ) 0, NULL, xTicksToWait );
950-
pxStreamBuffer->xTaskWaitingToSend = NULL;
950+
sbENTER_CRITICAL( pxStreamBuffer );
951+
{
952+
pxStreamBuffer->xTaskWaitingToSend = NULL;
953+
}
954+
sbEXIT_CRITICAL( pxStreamBuffer );
951955
} while( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE );
952956
}
953957
else
@@ -1171,7 +1175,11 @@ size_t xStreamBufferReceive( StreamBufferHandle_t xStreamBuffer,
11711175
/* Wait for data to be available. */
11721176
traceBLOCKING_ON_STREAM_BUFFER_RECEIVE( xStreamBuffer );
11731177
( void ) xTaskNotifyWaitIndexed( pxStreamBuffer->uxNotificationIndex, ( uint32_t ) 0, ( uint32_t ) 0, NULL, xTicksToWait );
1174-
pxStreamBuffer->xTaskWaitingToReceive = NULL;
1178+
sbENTER_CRITICAL( pxStreamBuffer );
1179+
{
1180+
pxStreamBuffer->xTaskWaitingToReceive = NULL;
1181+
}
1182+
sbEXIT_CRITICAL( pxStreamBuffer );
11751183

11761184
/* Recheck the data available after blocking. */
11771185
xBytesAvailable = prvBytesInBuffer( pxStreamBuffer );

0 commit comments

Comments
 (0)