mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-12 05:17:38 +00:00
fix(esp_ringbuf): Fixed a bug where in a no-split buffer received items prematurely
This commit fixes a bug in the no-split buffer which could receive an item prematurely if the space on the buffer is acquired until the buffer is full. The commit also adds a unit test for this scenario. Closes https://github.com/espressif/esp-idf/issues/14568
This commit is contained in:
@@ -506,6 +506,13 @@ static BaseType_t prvCheckItemAvail(Ringbuffer_t *pxRingbuffer)
|
||||
return pdFALSE; //Byte buffers do not allow multiple retrievals before return
|
||||
}
|
||||
if ((pxRingbuffer->xItemsWaiting > 0) && ((pxRingbuffer->pucRead != pxRingbuffer->pucWrite) || (pxRingbuffer->uxRingbufferFlags & rbBUFFER_FULL_FLAG))) {
|
||||
// If the ring buffer is a no-split buffer, the read pointer must point to an item that has been written to.
|
||||
if ((pxRingbuffer->uxRingbufferFlags & (rbBYTE_BUFFER_FLAG | rbALLOW_SPLIT_FLAG)) == 0) {
|
||||
ItemHeader_t *pxHeader = (ItemHeader_t *)pxRingbuffer->pucRead;
|
||||
if ((pxHeader->uxItemFlags & rbITEM_WRITTEN_FLAG) == 0) {
|
||||
return pdFALSE;
|
||||
}
|
||||
}
|
||||
return pdTRUE; //Items/data available for retrieval
|
||||
} else {
|
||||
return pdFALSE; //No items/data available for retrieval
|
||||
@@ -989,9 +996,6 @@ BaseType_t xRingbufferSendAcquire(RingbufHandle_t xRingbuffer, void **ppvItem, s
|
||||
if (xItemSize > pxRingbuffer->xMaxItemSize) {
|
||||
return pdFALSE; //Data will never ever fit in the queue.
|
||||
}
|
||||
if ((pxRingbuffer->uxRingbufferFlags & rbBYTE_BUFFER_FLAG) && xItemSize == 0) {
|
||||
return pdTRUE; //Sending 0 bytes to byte buffer has no effect
|
||||
}
|
||||
|
||||
return prvSendAcquireGeneric(pxRingbuffer, NULL, ppvItem, xItemSize, xTicksToWait);
|
||||
}
|
||||
|
Reference in New Issue
Block a user