freertos/ringbuf: Add an API xRingbufferGetCurFreeSize() to fetch current free size available

The earlier available API (xRingbufferGetMaxItemSize())just gives
a static max entry value possible for given ring buffer.
There was a feature request for an API which could provide
a real time available buffer size. See below:

https://github.com/espressif/esp-idf/issues/806

Signed-off-by: Piyush Shah <piyush@espressif.com>
This commit is contained in:
Piyush Shah
2017-11-20 19:23:25 +05:30
parent 7e3ac34704
commit cd5fb054c7
2 changed files with 80 additions and 1 deletions

View File

@@ -94,6 +94,21 @@ void vRingbufferDelete(RingbufHandle_t ringbuf);
*/
size_t xRingbufferGetMaxItemSize(RingbufHandle_t ringbuf);
/**
* @brief Get current free size available in the buffer
*
* This gives the real time free space available in the ring buffer. So basically,
* this will be the maximum size of the entry that can be sent into the buffer.
*
* @note This API is not thread safe. So, if multiple threads are accessing the same
* ring buffer, it is the application's responsibility to ensure atomic access to this
* API and the subsequent Send
*
* @param ringbuf - Ring buffer to query
*
* @return Current free size, in bytes, available for an entry
*/
size_t xRingbufferGetCurFreeSize(RingbufHandle_t ringbuf);
/**
* @brief Insert an item into the ring buffer