Skip to content

Commit

Permalink
🐛Add mutex control for printf and cout (#570)
Browse files Browse the repository at this point in the history
* Initial commit

* Added back a missing taskEXIT_CRITICAL()
  • Loading branch information
ryan-doan authored May 8, 2023
1 parent 0a07ddb commit 4c9b90b
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/rtos/stream_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,9 @@ TimeOut_t xTimeOut;
mtCOVERAGE_TEST_MARKER();
}

taskENTER_CRITICAL();
xReturn = prvWriteMessageToBuffer( pxStreamBuffer, pvTxData, xDataLengthBytes, xSpace, xRequiredSpace );
taskEXIT_CRITICAL();

if( xReturn > ( size_t ) 0 )
{
Expand Down Expand Up @@ -666,7 +668,9 @@ static size_t prvWriteMessageToBuffer( StreamBuffer_t * const pxStreamBuffer,
into the buffer. Start by writing the length of the data, the data
itself will be written later in this function. */
xShouldWrite = pdTRUE;
taskENTER_CRITICAL();
( void ) prvWriteBytesToBuffer( pxStreamBuffer, ( const uint8_t * ) &( xDataLengthBytes ), sbBYTES_TO_STORE_MESSAGE_LENGTH );
taskEXIT_CRITICAL();
}
else
{
Expand All @@ -677,7 +681,9 @@ static size_t prvWriteMessageToBuffer( StreamBuffer_t * const pxStreamBuffer,
if( xShouldWrite != pdFALSE )
{
/* Writes the data itself. */
taskENTER_CRITICAL();
xReturn = prvWriteBytesToBuffer( pxStreamBuffer, ( const uint8_t * ) pvTxData, xDataLengthBytes ); /*lint !e9079 Storage buffer is implemented as uint8_t for ease of sizing, alighment and access. */
taskEXIT_CRITICAL();
}
else
{
Expand Down Expand Up @@ -864,7 +870,9 @@ size_t xOriginalTail, xReceivedLength, xNextMessageLength;
returned to its prior state if the length of the message is too
large for the provided buffer. */
xOriginalTail = pxStreamBuffer->xTail;
taskENTER_CRITICAL();
( void ) prvReadBytesFromBuffer( pxStreamBuffer, ( uint8_t * ) &xNextMessageLength, xBytesToStoreMessageLength, xBytesAvailable );
taskEXIT_CRITICAL();

/* Reduce the number of bytes available by the number of bytes just
read out. */
Expand Down Expand Up @@ -893,7 +901,9 @@ size_t xOriginalTail, xReceivedLength, xNextMessageLength;
}

/* Read the actual data. */
taskENTER_CRITICAL();
xReceivedLength = prvReadBytesFromBuffer( pxStreamBuffer, ( uint8_t * ) pvRxData, xNextMessageLength, xBytesAvailable ); /*lint !e9079 Data storage area is implemented as uint8_t array for ease of sizing, indexing and alignment. */
taskEXIT_CRITICAL();

return xReceivedLength;
}
Expand Down

0 comments on commit 4c9b90b

Please sign in to comment.