]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: dynbuf: add functions to help queue/requeue buffer_wait fields
authorWilly Tarreau <w@1wt.eu>
Tue, 23 Apr 2024 17:00:22 +0000 (19:00 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 10 May 2024 15:18:13 +0000 (17:18 +0200)
When failing an allocation we always do the same dance, add the
buffer_wait struct to a list if it's not, and return. Let's just add
dedicated functions to centralize this, this will be useful to implement
a bit more complex logic.

For now they're not used.

include/haproxy/dynbuf-t.h
include/haproxy/dynbuf.h

index ed229bc36e32692e81ae3242d8e3d1b2d77b1693..b64cda144f41621340217a2fb6e152857c5be0e5 100644 (file)
 enum dynbuf_crit {
        DB_GROW_RING = 0, // used to grow an existing buffer ring
        DB_UNLIKELY,      // unlikely to be needed (e.g. L7 retries)
+       /* The 4 levels below are subject to queueing */
        DB_MUX_RX,        // buffer used to store incoming data from the system
        DB_SE_RX,         // buffer used to store incoming data for the channel
        DB_CHANNEL,       // buffer used by the channel for synchronous reads
        DB_MUX_TX,        // buffer used to store outgoing mux data
+       /* The one below may never fail */
        DB_PERMANENT,     // buffers permanently allocated.
 };
 
index b8407951c92c8f29db4368ec188c0e7dff977e55..4541281ee9f09e02af5371217f9fdbffbeaeb86f 100644 (file)
@@ -121,6 +121,39 @@ static inline void offer_buffers(void *from, unsigned int count)
                __offer_buffers(from, count);
 }
 
+/* Queues a buffer request for the current thread via <bw>, and returns
+ * non-zero if the criticality allows to queue a request, otherwise returns
+ * zero. If the <bw> was already queued, non-zero is returned so that the call
+ * is idempotent. It is assumed that the buffer_wait struct had already been
+ * preset with its context and callback, otherwise please use b_queue()
+ * instead.
+ */
+static inline int b_requeue(enum dynbuf_crit crit, struct buffer_wait *bw)
+{
+       if (LIST_INLIST(&bw->list))
+               return 1;
+
+       /* these ones are never queued */
+       if (crit < DB_MUX_RX)
+               return 0;
+
+       LIST_APPEND(&th_ctx->buffer_wq, &bw->list);
+       return 1;
+}
+
+/* Queues a buffer request for the current thread via <bw> with the given <ctx>
+ * and <cb>, and returns non-zero if the criticality allows to queue a request,
+ * otherwise returns zero. If the <bw> was already queued, non-zero is returned
+ * so that the call is idempotent.  If the buffer_wait struct had already been
+ * preset with the ctx and cb, please use the lighter b_requeue() instead.
+ */
+static inline int b_queue(enum dynbuf_crit crit, struct buffer_wait *bw, void *ctx, int (*cb)(void *))
+{
+       bw->target    = ctx;
+       bw->wakeup_cb = cb;
+       return b_requeue(crit, bw);
+}
+
 
 #endif /* _HAPROXY_DYNBUF_H */