]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: dynbuf: provide a b_dequeue() function to detach a bw from the queue
authorWilly Tarreau <w@1wt.eu>
Wed, 24 Apr 2024 16:31:14 +0000 (18:31 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 10 May 2024 15:18:13 +0000 (17:18 +0200)
Now that we need to keep the bitmap in sync with the list heads, we don't
want tasks to leave just doing a LIST_DEL_INIT() without updating the map.
Let's provide a b_dequeue() function for that purpose. The function detects
when it's going to remove the last element and figures the queue number
based on the pointer since it points to the root. It's not used yet.

include/haproxy/dynbuf.h

index d8a7552fc57eef9f9d3bcadf8f5fe9d39249288d..21f347b4fbcfe9626984a0aa0cbee27a72d45e65 100644 (file)
@@ -168,6 +168,29 @@ static inline int b_queue(enum dynbuf_crit crit, struct buffer_wait *bw, void *c
        return b_requeue(crit, bw);
 }
 
+/* Dequeues bw element <bw> from its list and updates the bufq_map if if was
+ * the last element. All users of buffer_wait should use this to dequeue (e.g.
+ * when killing a pending request on timeout) so as to make sure that we keep
+ * consistency between the list heads and the bitmap.
+ */
+static inline void b_dequeue(struct buffer_wait *bw)
+{
+       uint q;
+
+       if (likely(!LIST_INLIST(&bw->list)))
+               return;
+
+       /* trick: detect if we're the last one and pointing to a root, so we
+        * can figure the queue number since the root belongs to an array.
+        */
+       if (LIST_ATMOST1(&bw->list)) {
+               /* OK then which root? */
+               q = bw->list.n - &th_ctx->buffer_wq[0];
+               BUG_ON_HOT(q >= DYNBUF_NBQ);
+               th_ctx->bufq_map &= ~(1 << q);
+       }
+       LIST_DEL_INIT(&bw->list);
+}
 
 #endif /* _HAPROXY_DYNBUF_H */