Skip to content

Commit fccb97b

Browse files
authored
No functional changes. (#194)
Shorted overly verbose and opinionated comments in xStreamBufferSend(). Remove the unnecessary xIsFeasible variable from xStreamBufferSend().
1 parent b1307db commit fccb97b

File tree

1 file changed

+11
-35
lines changed

1 file changed

+11
-35
lines changed

stream_buffer.c

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -518,10 +518,6 @@ size_t xStreamBufferSend( StreamBufferHandle_t xStreamBuffer,
518518
size_t xRequiredSpace = xDataLengthBytes;
519519
TimeOut_t xTimeOut;
520520

521-
/* Having a 'isFeasible' variable allows to respect the convention that there is only a return statement at the end. Othewise, return
522-
* could be done as soon as we realise the send cannot happen. We will let the call to 'prvWriteMessageToBuffer' dealing with this scenario. */
523-
BaseType_t xIsFeasible;
524-
525521
configASSERT( pvTxData );
526522
configASSERT( pxStreamBuffer );
527523

@@ -536,55 +532,35 @@ size_t xStreamBufferSend( StreamBufferHandle_t xStreamBuffer,
536532
/* Overflow? */
537533
configASSERT( xRequiredSpace > xDataLengthBytes );
538534

539-
/* In the case of the message buffer, one has to be able to write the complete message as opposed to
540-
* a stream buffer for semantic reasons. Check if it is physically possible to write the message given
541-
* the length of the buffer. */
535+
/* If this is a message buffer then it must be possible to write the
536+
* whole message. */
542537
if( xRequiredSpace > pxStreamBuffer->xLength )
543538
{
544-
/* The message could never be written because it is greater than the buffer length.
545-
* By setting xIsFeasable to FALSE, we skip over the following do..while loop, thus avoiding
546-
* a deadlock. The call to 'prvWriteMessageToBuffer' toward the end of this function with
547-
* xRequiredSpace greater than xSpace will suffice in not writing anything to the internal buffer.
548-
* Now, the function will return 0 because the message could not be written. Should an error code be
549-
* returned instead ??? In my opinion, probably.. But the return type doesn't allow for negative
550-
* values to be returned. A confusion could exist to the caller. Returning 0 because a timeout occurred
551-
* and a subsequent send attempts could eventually succeed, and returning 0 because a write could never
552-
* happen because of the size are two scenarios to me :/ */
553-
xIsFeasible = pdFALSE;
539+
/* The message would not fit even if the entire buffer was empty,
540+
* so don't wait for space. */
541+
xTicksToWait = ( TickType_t ) 0;
554542
}
555543
else
556544
{
557-
/* It is possible to write the message completely in the buffer. This is the intended route.
558-
* Let's continue with the regular timeout logic. */
559-
xIsFeasible = pdTRUE;
545+
mtCOVERAGE_TEST_MARKER();
560546
}
561547
}
562548
else
563549
{
564-
/* In the case of the stream buffer, not being able to completely write the message in the buffer
565-
* is an acceptable scenario, but it has to be dealt with properly */
550+
/* If this is a stream buffer then it is acceptable to write only part
551+
* of the message to the buffer. Cap the length to the total length of
552+
* the buffer. */
566553
if( xRequiredSpace > pxStreamBuffer->xLength )
567554
{
568-
/* Not enough buffer space. We will attempt to write as much as we can in this run
569-
* so that the caller can send the remaining in subsequent calls. We avoid a deadlock by
570-
* offering the possibility to take the 'else' branch in the 'if( xSpace < xRequiredSpace )'
571-
* condition inside the following do..while loop */
572555
xRequiredSpace = pxStreamBuffer->xLength;
573-
574-
/* TODO FIXME: Is there a check we should do with the xTriggerLevelBytes value ? */
575-
576-
/* With the adjustment to 'xRequiredSpace', the deadlock is avoided, thus it's now feasible. */
577-
xIsFeasible = pdTRUE;
578556
}
579557
else
580558
{
581-
/* It is possible to write the message completely in the buffer. */
582-
xIsFeasible = pdTRUE;
559+
mtCOVERAGE_TEST_MARKER();
583560
}
584561
}
585562

586-
/* Added check against xIsFeasible. If it's not feasible, don't even wait for notification, let the call to 'prvWriteMessageToBuffer' do nothing and return 0 */
587-
if( ( xTicksToWait != ( TickType_t ) 0 ) && ( xIsFeasible == pdTRUE ) )
563+
if( xTicksToWait != ( TickType_t ) 0 )
588564
{
589565
vTaskSetTimeOutState( &xTimeOut );
590566

0 commit comments

Comments
 (0)