fix(esp_ringbuf): Fixed no-split ringbuf issue where acquire pointer wraps around

This commit fixes an issue with no-split ring buffers where in the the
buffer did not receive items correctly if the acquire pointer wraps
around before items are sent to it.
This commit is contained in:
Sudeep Mohanty
2024-12-05 13:06:00 +05:30
parent 6a4a124d65
commit e81925a681
2 changed files with 89 additions and 1 deletions

View File

@@ -386,7 +386,7 @@ static void prvSendItemDoneNoSplit(Ringbuffer_t *pxRingbuffer, uint8_t* pucItem)
*/
pxCurHeader = (ItemHeader_t *)pxRingbuffer->pucWrite;
//Skip over Items that have already been written or are dummy items
while (((pxCurHeader->uxItemFlags & rbITEM_WRITTEN_FLAG) || (pxCurHeader->uxItemFlags & rbITEM_DUMMY_DATA_FLAG)) && pxRingbuffer->pucWrite != pxRingbuffer->pucAcquire) {
while (((pxCurHeader->uxItemFlags & rbITEM_WRITTEN_FLAG) || (pxCurHeader->uxItemFlags & rbITEM_DUMMY_DATA_FLAG))) {
if (pxCurHeader->uxItemFlags & rbITEM_DUMMY_DATA_FLAG) {
pxCurHeader->uxItemFlags |= rbITEM_WRITTEN_FLAG; //Mark as freed (not strictly necessary but adds redundancy)
pxRingbuffer->pucWrite = pxRingbuffer->pucHead; //Wrap around due to dummy data
@@ -401,6 +401,12 @@ static void prvSendItemDoneNoSplit(Ringbuffer_t *pxRingbuffer, uint8_t* pucItem)
if ((pxRingbuffer->pucTail - pxRingbuffer->pucWrite) < rbHEADER_SIZE) {
pxRingbuffer->pucWrite = pxRingbuffer->pucHead;
}
// If the write pointer has caught up to the acquire pointer, we can break out of the loop
if (pxRingbuffer->pucWrite == pxRingbuffer->pucAcquire) {
break;
}
pxCurHeader = (ItemHeader_t *)pxRingbuffer->pucWrite; //Update header to point to item
}
}