From 2305b5f474dff37ade48012afc81b05f5fa24111 Mon Sep 17 00:00:00 2001 From: RichFalk Date: Sun, 17 Oct 2021 20:58:00 -0700 Subject: [PATCH] esp_ringbuf: Fix assertion xQueueGenericSend queue.c:818 The release of the semaphore indicating the item was successfully sent must be the last semaphore released. The receiver may be in another task and may delete the Ringbuffer (such as with a return code across tasks design pattern) if they are through with the Ringbuffer. The function xRingbufferSendAcquire followed by xRingbufferSendComplete had the semaphores released in the proper order and that same pattern should have been used in xRingbufferSend and xRingbufferSendFromISR. This commit fixes this order. Issue (IDFGH-6030) #7716 describes the problem in more detail. Closes IDFGH-6030, https://github.com/espressif/esp-idf/issues/7716 Closes IDFGH-6036, https://github.com/espressif/esp-idf/pull/7721 --- components/esp_ringbuf/ringbuf.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/components/esp_ringbuf/ringbuf.c b/components/esp_ringbuf/ringbuf.c index f8c62d03c7..241010f6f6 100644 --- a/components/esp_ringbuf/ringbuf.c +++ b/components/esp_ringbuf/ringbuf.c @@ -1,4 +1,4 @@ -// Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD +// Copyright 2015-2021 Espressif Systems (Shanghai) PTE LTD // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -1041,13 +1041,13 @@ BaseType_t xRingbufferSend(RingbufHandle_t xRingbuffer, */ } + if (xReturnSemaphore == pdTRUE) { + xSemaphoreGive(rbGET_TX_SEM_HANDLE(pxRingbuffer)); //Give back semaphore so other tasks can send + } if (xReturn == pdTRUE) { //Indicate item was successfully sent xSemaphoreGive(rbGET_RX_SEM_HANDLE(pxRingbuffer)); } - if (xReturnSemaphore == pdTRUE) { - xSemaphoreGive(rbGET_TX_SEM_HANDLE(pxRingbuffer)); //Give back semaphore so other tasks can send - } return xReturn; } @@ -1083,13 +1083,13 @@ BaseType_t xRingbufferSendFromISR(RingbufHandle_t xRingbuffer, } portEXIT_CRITICAL_ISR(&pxRingbuffer->mux); + if (xReturnSemaphore == pdTRUE) { + xSemaphoreGiveFromISR(rbGET_TX_SEM_HANDLE(pxRingbuffer), pxHigherPriorityTaskWoken); //Give back semaphore so other tasks can send + } if (xReturn == pdTRUE) { //Indicate item was successfully sent xSemaphoreGiveFromISR(rbGET_RX_SEM_HANDLE(pxRingbuffer), pxHigherPriorityTaskWoken); } - if (xReturnSemaphore == pdTRUE) { - xSemaphoreGiveFromISR(rbGET_TX_SEM_HANDLE(pxRingbuffer), pxHigherPriorityTaskWoken); //Give back semaphore so other tasks can send - } return xReturn; }