0 : ring->storage->size) + tail - ring->storage->head;
}
-/* returns the allocated size in bytes for the ring */
+/* returns the usable size in bytes for the ring. It is smaller than
+ * the allocate size by the size of the ring_storage header.
+ */
static inline size_t ring_size(const struct ring *ring)
{
return ring->storage->size;
}
+/* returns the allocated size in bytes for the ring. It covers the whole
+ * area made of both the ring_storage and the usable area.
+ */
+static inline size_t ring_allocated_size(const struct ring *ring)
+{
+ return ring->storage->size + ring->storage->rsvd;
+}
+
/* returns the head offset of the ring */
static inline size_t ring_head(const struct ring *ring)
{
}
/* Creates and returns a ring buffer of size <size> bytes. Returns NULL on
- * allocation failure.
+ * allocation failure. The size is the area size, not the usable size.
*/
struct ring *ring_new(size_t size)
{
/* Resizes existing ring <ring> to <size> which must be larger, without losing
* its contents. The new size must be at least as large as the previous one or
* no change will be performed. The pointer to the ring is returned on success,
- * or NULL on allocation failure. This will lock the ring for writes.
+ * or NULL on allocation failure. This will lock the ring for writes. The size
+ * is the allocated area size, and includes the ring_storage header.
*/
struct ring *ring_resize(struct ring *ring, size_t size)
{