diff --git a/include/haproxy/applet.h b/include/haproxy/applet.h index 68f98e2e3..1fb3b260d 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 2b015a01a..47263bcd5 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;