From: Willy Tarreau Date: Thu, 16 Mar 2023 16:30:04 +0000 (+0100) Subject: MINOR: buffer: add br_single() to check if a buffer ring has more than one buf X-Git-Tag: v2.8-dev6~55 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9824f8c8908d67f6cedf2434e12a23f18a27eaf0;p=thirdparty%2Fhaproxy.git MINOR: buffer: add br_single() to check if a buffer ring has more than one buf It's cheaper and cleaner than using br_count()==1 given that it just compares two indexes, and that a ring having a single buffer is in a special case where it is between empty and used up-to-1. In other words it's not congested. --- diff --git a/include/haproxy/buf.h b/include/haproxy/buf.h index 1136a6a9bb..e98161ebee 100644 --- a/include/haproxy/buf.h +++ b/include/haproxy/buf.h @@ -1027,6 +1027,14 @@ static inline unsigned int br_count(const struct buffer *r) return r->data + r->size - r->head; } +/* Returns true if a single buffer is assigned */ +static inline unsigned int br_single(const struct buffer *r) +{ + BUG_ON_HOT(r->area != BUF_RING.area); + + return r->data == r->head; +} + /* Returns the index of the ring's head buffer */ static inline unsigned int br_head_idx(const struct buffer *r) {