mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-09-13 01:27:48 -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
|
@ -497,11 +497,19 @@ size_t xStreamBufferSpacesAvailable( StreamBufferHandle_t xStreamBuffer )
|
||||||
{
|
{
|
||||||
const StreamBuffer_t * const pxStreamBuffer = xStreamBuffer;
|
const StreamBuffer_t * const pxStreamBuffer = xStreamBuffer;
|
||||||
size_t xSpace;
|
size_t xSpace;
|
||||||
|
volatile size_t xOriginalTail;
|
||||||
|
|
||||||
configASSERT( pxStreamBuffer );
|
configASSERT( pxStreamBuffer );
|
||||||
|
|
||||||
xSpace = pxStreamBuffer->xLength + pxStreamBuffer->xTail;
|
/* The code below reads xTail and then xHead. This is safe if the stream
|
||||||
xSpace -= pxStreamBuffer->xHead;
|
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;
|
xSpace -= ( size_t ) 1;
|
||||||
|
|
||||||
if( xSpace >= pxStreamBuffer->xLength )
|
if( xSpace >= pxStreamBuffer->xLength )
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue