MINOR: dynbuf: add functions to help queue/requeue buffer_wait fields

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.
This commit is contained in:
Willy Tarreau 2024-04-23 19:00:22 +02:00
parent 72d0dcda8e
commit d1c2f325a2
2 changed files with 35 additions and 0 deletions

View File

@ -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.
};

View 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 */