mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-06 07:07:04 +02:00
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:
parent
72d0dcda8e
commit
d1c2f325a2
@ -52,10 +52,12 @@
|
|||||||
enum dynbuf_crit {
|
enum dynbuf_crit {
|
||||||
DB_GROW_RING = 0, // used to grow an existing buffer ring
|
DB_GROW_RING = 0, // used to grow an existing buffer ring
|
||||||
DB_UNLIKELY, // unlikely to be needed (e.g. L7 retries)
|
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_MUX_RX, // buffer used to store incoming data from the system
|
||||||
DB_SE_RX, // buffer used to store incoming data for the channel
|
DB_SE_RX, // buffer used to store incoming data for the channel
|
||||||
DB_CHANNEL, // buffer used by the channel for synchronous reads
|
DB_CHANNEL, // buffer used by the channel for synchronous reads
|
||||||
DB_MUX_TX, // buffer used to store outgoing mux data
|
DB_MUX_TX, // buffer used to store outgoing mux data
|
||||||
|
/* The one below may never fail */
|
||||||
DB_PERMANENT, // buffers permanently allocated.
|
DB_PERMANENT, // buffers permanently allocated.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -121,6 +121,39 @@ static inline void offer_buffers(void *from, unsigned int count)
|
|||||||
__offer_buffers(from, 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 */
|
#endif /* _HAPROXY_DYNBUF_H */
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user