mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-22 06:11:32 +02:00
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.
This commit is contained in:
parent
f12f32a0fa
commit
009e42bc59
24
src/applet.c
24
src/applet.c
@ -26,25 +26,7 @@ unsigned int nb_applets = 0;
|
|||||||
|
|
||||||
DECLARE_POOL(pool_head_appctx, "appctx", sizeof(struct appctx));
|
DECLARE_POOL(pool_head_appctx, "appctx", sizeof(struct appctx));
|
||||||
|
|
||||||
/* Initializes all required fields for a new appctx. Note that it does the
|
/* Tries to allocate a new appctx and initialize all of its fields. The appctx
|
||||||
* 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
|
|
||||||
* is returned on success, NULL on failure. The appctx must be released using
|
* is returned on success, NULL on failure. The appctx must be released using
|
||||||
* appctx_free(). <applet> is assigned as the applet, but it can be NULL. The
|
* appctx_free(). <applet> is assigned as the applet, but it can be NULL. The
|
||||||
* applet's task is always created on the current thread.
|
* 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;
|
struct appctx *appctx;
|
||||||
|
|
||||||
appctx = pool_alloc(pool_head_appctx);
|
appctx = pool_zalloc(pool_head_appctx);
|
||||||
if (unlikely(!appctx))
|
if (unlikely(!appctx))
|
||||||
goto fail_appctx;
|
goto fail_appctx;
|
||||||
|
|
||||||
appctx_init(appctx);
|
LIST_INIT(&appctx->wait_entry);
|
||||||
appctx->obj_type = OBJ_TYPE_APPCTX;
|
appctx->obj_type = OBJ_TYPE_APPCTX;
|
||||||
appctx->applet = applet;
|
appctx->applet = applet;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user