]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: buffer: add br_count() to return the number of allocated bufs
authorWilly Tarreau <w@1wt.eu>
Thu, 16 Mar 2023 15:46:56 +0000 (16:46 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 16 Mar 2023 17:45:46 +0000 (18:45 +0100)
We have no way to know how many buffers are currently allocated in a
buffer ring. Let's add br_count() for this.

include/haproxy/buf.h

index 417ff9c8e2c37bc887316a62f52854f8bc9d1dce..1136a6a9bbc44bf52524b6e1f1fc573cad6bf339 100644 (file)
@@ -1016,6 +1016,17 @@ static inline unsigned int br_full(const struct buffer *r)
        return r->data + 1 == r->head || r->data + 1 == r->head - 1 + r->size;
 }
 
+/* Returns the number of buffers present */
+static inline unsigned int br_count(const struct buffer *r)
+{
+       BUG_ON_HOT(r->area != BUF_RING.area);
+
+       if (r->data >= r->head)
+               return r->data - r->head + 1;
+       else
+               return r->data + r->size - r->head;
+}
+
 /* Returns the index of the ring's head buffer */
 static inline unsigned int br_head_idx(const struct buffer *r)
 {