mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-09-12 17:17:44 -04:00
Apply SpacesAvailable() fix
Original author: RichardBarry
This commit is contained in:
parent
4223fd5326
commit
1e4aab6d40
1 changed files with 11 additions and 3 deletions
|
@ -280,7 +280,7 @@ static void prvInitialiseNewStreamBuffer( StreamBuffer_t * const pxStreamBuffer,
|
|||
{
|
||||
pucAllocatedMemory = NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if( pucAllocatedMemory != NULL )
|
||||
{
|
||||
|
@ -497,11 +497,19 @@ size_t xStreamBufferSpacesAvailable( StreamBufferHandle_t xStreamBuffer )
|
|||
{
|
||||
const StreamBuffer_t * const pxStreamBuffer = xStreamBuffer;
|
||||
size_t xSpace;
|
||||
volatile size_t xOriginalTail;
|
||||
|
||||
configASSERT( pxStreamBuffer );
|
||||
|
||||
xSpace = pxStreamBuffer->xLength + pxStreamBuffer->xTail;
|
||||
xSpace -= pxStreamBuffer->xHead;
|
||||
/* The code below reads xTail and then xHead. This is safe if the stream
|
||||
buffer is updated once between the two reads - but not if the stream buffer
|
||||
is updated more than once between the two reads - hence the loop. */
|
||||
do
|
||||
{
|
||||
xOriginalTail = pxStreamBuffer->xTail;
|
||||
xSpace = pxStreamBuffer->xLength + pxStreamBuffer->xTail;
|
||||
xSpace -= pxStreamBuffer->xHead;
|
||||
} while( xOriginalTail != pxStreamBuffer->xTail );
|
||||
xSpace -= ( size_t ) 1;
|
||||
|
||||
if( xSpace >= pxStreamBuffer->xLength )
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue