diff --git a/include/haproxy/dynbuf-t.h b/include/haproxy/dynbuf-t.h index ed229bc36..b64cda144 100644 --- a/include/haproxy/dynbuf-t.h +++ b/include/haproxy/dynbuf-t.h @@ -52,10 +52,12 @@ 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. }; diff --git a/include/haproxy/dynbuf.h b/include/haproxy/dynbuf.h index b8407951c..4541281ee 100644 --- a/include/haproxy/dynbuf.h +++ b/include/haproxy/dynbuf.h @@ -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 , and returns + * non-zero if the criticality allows to queue a request, otherwise returns + * zero. If the 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 with the given + * and , and returns non-zero if the criticality allows to queue a request, + * otherwise returns zero. If the 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 */