From: Willy Tarreau Date: Wed, 15 Jun 2022 14:35:51 +0000 (+0200) Subject: MEDIUM: applet: only keep appctx_new_*() and drop appctx_new() X-Git-Tag: v2.7-dev2~152 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=cb8542755ec040215f66a630143a412ff5228260;p=thirdparty%2Fhaproxy.git MEDIUM: applet: only keep appctx_new_*() and drop appctx_new() This removes the mask-based variant so that from now on the low-level function becomes appctx_new_on() and it takes either a thread number or a negative value for "any thread". This way we can use task_new_on() and task_new_anywhere() instead of task_new() which will soon disappear. --- diff --git a/include/haproxy/applet.h b/include/haproxy/applet.h index 68f98e2e35..1fb3b260de 100644 --- a/include/haproxy/applet.h +++ b/include/haproxy/applet.h @@ -42,23 +42,18 @@ int appctx_buf_available(void *arg); void *applet_reserve_svcctx(struct appctx *appctx, size_t size); void appctx_shut(struct appctx *appctx); -struct appctx *appctx_new(struct applet *applet, struct sedesc *sedesc, unsigned long thread_mask); +struct appctx *appctx_new_on(struct applet *applet, struct sedesc *sedesc, int thr); int appctx_finalize_startup(struct appctx *appctx, struct proxy *px, struct buffer *input); void appctx_free_on_early_error(struct appctx *appctx); -static inline struct appctx *appctx_new_on(struct applet *applet, struct sedesc *sedesc, uint thr) -{ - return appctx_new(applet, sedesc, 1UL << thr); -} - static inline struct appctx *appctx_new_here(struct applet *applet, struct sedesc *sedesc) { - return appctx_new(applet, sedesc, tid_bit); + return appctx_new_on(applet, sedesc, tid); } static inline struct appctx *appctx_new_anywhere(struct applet *applet, struct sedesc *sedesc) { - return appctx_new(applet, sedesc, all_threads_mask); + return appctx_new_on(applet, sedesc, -1); } /* Helper function to call .init applet callback function, if it exists. Returns 0 diff --git a/src/applet.c b/src/applet.c index 2b015a01ab..47263bcd5c 100644 --- a/src/applet.c +++ b/src/applet.c @@ -28,15 +28,17 @@ DECLARE_POOL(pool_head_appctx, "appctx", sizeof(struct 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. + * appctx_free(). is assigned as the applet, but it can be NULL. + * is the thread ID to start the applet on, and a negative value allows the + * applet to start anywhere. Backend applets may only be created on the current + * thread. */ -struct appctx *appctx_new(struct applet *applet, struct sedesc *sedesc, unsigned long thread_mask) +struct appctx *appctx_new_on(struct applet *applet, struct sedesc *sedesc, int thr) { struct appctx *appctx; /* Backend appctx cannot be started on another thread than the local one */ - BUG_ON(thread_mask != tid_bit && sedesc); + BUG_ON(thr != tid && sedesc); appctx = pool_zalloc(pool_head_appctx); if (unlikely(!appctx)) @@ -55,7 +57,11 @@ struct appctx *appctx_new(struct applet *applet, struct sedesc *sedesc, unsigned } appctx->sedesc = sedesc; - appctx->t = task_new(thread_mask); + if (thr >= 0) + appctx->t = task_new_on(thr); + else + appctx->t = task_new_anywhere(); + if (unlikely(!appctx->t)) goto fail_task; appctx->t->process = task_run_applet;