MINOR: applet: set the blocking flag in the buffer allocation function

Instead of having each caller of appctx_get_buf() think about setting
the blocking flag, better have the function do it, since it's already
handling the queue anyway. This way we're sure that both are consistent.
This commit is contained in:
Willy Tarreau 2024-05-07 19:16:20 +02:00
parent ee0d56ac85
commit 4ffb3b5ebe
5 changed files with 10 additions and 9 deletions

View File

@ -59,6 +59,7 @@ size_t appctx_snd_buf(struct stconn *sc, struct buffer *buf, size_t count, unsig
int appctx_fastfwd(struct stconn *sc, unsigned int count, unsigned int flags);
ssize_t applet_append_line(void *ctx, struct ist v1, struct ist v2, size_t ofs, size_t len);
static forceinline void applet_fl_set(struct appctx *appctx, uint on);
static inline struct appctx *appctx_new_here(struct applet *applet, struct sedesc *sedesc)
{
@ -84,15 +85,20 @@ static inline void appctx_release_buf(struct appctx *appctx, struct buffer *bptr
}
/*
* Allocate a buffer. If if fails, it adds the appctx in buffer wait queue.
* Allocate a buffer. If if fails, it adds the appctx in buffer wait queue and
* sets the relevant blocking flag depending on the side (assuming that bptr is
* either &appctx->inbuf or &appctx->outbuf)
*/
static inline struct buffer *appctx_get_buf(struct appctx *appctx, struct buffer *bptr)
{
struct buffer *buf = NULL;
int is_inbuf = (bptr == &appctx->inbuf);
if (likely(!LIST_INLIST(&appctx->buffer_wait.list)) &&
unlikely((buf = b_alloc(bptr, DB_SE_RX)) == NULL)) {
b_queue(DB_SE_RX, &appctx->buffer_wait, appctx, appctx_buf_available);
if (likely(!LIST_INLIST(&appctx->buffer_wait.list))) {
if (unlikely((buf = b_alloc(bptr, DB_SE_RX)) == NULL)) {
b_queue(DB_SE_RX, &appctx->buffer_wait, appctx, appctx_buf_available);
applet_fl_set(appctx, is_inbuf ? APPCTX_FL_INBLK_ALLOC : APPCTX_FL_OUTBLK_ALLOC);
}
}
return buf;
}

View File

@ -528,7 +528,6 @@ size_t appctx_rcv_buf(struct stconn *sc, struct buffer *buf, size_t count, unsig
goto end;
if (!appctx_get_buf(appctx, &appctx->outbuf)) {
applet_fl_set(appctx, APPCTX_FL_OUTBLK_ALLOC);
TRACE_STATE("waiting for appctx outbuf allocation", APPLET_EV_RECV|APPLET_EV_BLK, appctx);
goto end;
}
@ -626,7 +625,6 @@ size_t appctx_snd_buf(struct stconn *sc, struct buffer *buf, size_t count, unsig
goto end;
if (!appctx_get_buf(appctx, &appctx->inbuf)) {
applet_fl_set(appctx, APPCTX_FL_INBLK_ALLOC);
TRACE_STATE("waiting for appctx inbuf allocation", APPLET_EV_SEND|APPLET_EV_BLK, appctx);
goto end;
}

View File

@ -1790,7 +1790,6 @@ static void http_cache_io_handler(struct appctx *appctx)
goto exit;
if (!appctx_get_buf(appctx, &appctx->outbuf)) {
applet_fl_set(appctx, APPCTX_FL_OUTBLK_ALLOC);
goto exit;
}

View File

@ -1058,7 +1058,6 @@ static void cli_io_handler(struct appctx *appctx)
goto out;
if (!appctx_get_buf(appctx, &appctx->outbuf)) {
applet_fl_set(appctx, APPCTX_FL_OUTBLK_ALLOC);
goto out;
}

View File

@ -1955,7 +1955,6 @@ static void http_stats_io_handler(struct appctx *appctx)
goto out;
if (!appctx_get_buf(appctx, &appctx->outbuf)) {
applet_fl_set(appctx, APPCTX_FL_OUTBLK_ALLOC);
goto out;
}