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.
This commit is contained in:
Willy Tarreau 2022-06-15 16:35:51 +02:00
parent 0ad00befc1
commit cb8542755e
2 changed files with 14 additions and 13 deletions

View File

@ -42,23 +42,18 @@ int appctx_buf_available(void *arg);
void *applet_reserve_svcctx(struct appctx *appctx, size_t size); void *applet_reserve_svcctx(struct appctx *appctx, size_t size);
void appctx_shut(struct appctx *appctx); 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); int appctx_finalize_startup(struct appctx *appctx, struct proxy *px, struct buffer *input);
void appctx_free_on_early_error(struct appctx *appctx); 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) 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) 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 /* Helper function to call .init applet callback function, if it exists. Returns 0

View File

@ -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 /* 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 * 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. <thr>
* applet's task is always created on the current thread. * 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; struct appctx *appctx;
/* Backend appctx cannot be started on another thread than the local one */ /* 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); appctx = pool_zalloc(pool_head_appctx);
if (unlikely(!appctx)) if (unlikely(!appctx))
@ -55,7 +57,11 @@ struct appctx *appctx_new(struct applet *applet, struct sedesc *sedesc, unsigned
} }
appctx->sedesc = sedesc; 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)) if (unlikely(!appctx->t))
goto fail_task; goto fail_task;
appctx->t->process = task_run_applet; appctx->t->process = task_run_applet;