From 009e42bc59709b032ad7d1c3f5c0310c4bb0b5bf Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Thu, 5 May 2022 19:55:03 +0200 Subject: [PATCH] CLEANUP: applet: make appctx_new() initialize the whole appctx Till now, appctx_new() used to allocate an entry from the pool and pass it through appctx_init() to initialize a debatable part of it that didn't correspond anymore to the comments, and fill other fields. It's hard to say what is fully initialized and what is not. Let's get rid of that, and always zero the initialization (appctx are not that big anyway, even with the cache there's no difference in performance), and initialize what remains. this is cleaner and more resistant to new field additions. The appctx_init() function was removed. --- src/applet.c | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/src/applet.c b/src/applet.c index 81b8bacbe..381c36e6d 100644 --- a/src/applet.c +++ b/src/applet.c @@ -26,25 +26,7 @@ unsigned int nb_applets = 0; DECLARE_POOL(pool_head_appctx, "appctx", sizeof(struct appctx)); -/* Initializes all required fields for a new appctx. Note that it does the - * minimum acceptable initialization for an appctx. This means only the - * 3 integer states st0, st1, st2 and the chunk used to gather unfinished - * commands are zeroed - */ -static inline void appctx_init(struct appctx *appctx) -{ - appctx->st0 = appctx->st1 = appctx->st2 = 0; - appctx->chunk = NULL; - appctx->io_release = NULL; - appctx->call_rate.curr_tick = 0; - appctx->call_rate.curr_ctr = 0; - appctx->call_rate.prev_ctr = 0; - appctx->state = 0; - memset(&appctx->svc, 0, sizeof(appctx->svc)); - LIST_INIT(&appctx->wait_entry); -} - -/* Tries to allocate a new appctx and initialize its main fields. The appctx +/* Tries to allocate a new appctx and initialize all of its fields. The appctx * is returned on success, NULL on failure. The appctx must be released using * appctx_free(). is assigned as the applet, but it can be NULL. The * applet's task is always created on the current thread. @@ -53,11 +35,11 @@ struct appctx *appctx_new(struct applet *applet, struct cs_endpoint *endp) { struct appctx *appctx; - appctx = pool_alloc(pool_head_appctx); + appctx = pool_zalloc(pool_head_appctx); if (unlikely(!appctx)) goto fail_appctx; - appctx_init(appctx); + LIST_INIT(&appctx->wait_entry); appctx->obj_type = OBJ_TYPE_APPCTX; appctx->applet = applet;