]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: applet: only keep appctx_new_*() and drop appctx_new()
authorWilly Tarreau <w@1wt.eu>
Wed, 15 Jun 2022 14:35:51 +0000 (16:35 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 1 Jul 2022 17:15:14 +0000 (19:15 +0200)
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.

include/haproxy/applet.h
src/applet.c

index 68f98e2e356375fdfebc00e528e729c92fe64300..1fb3b260dec68adabd14b407d6cf7612957adf34 100644 (file)
@@ -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
index 2b015a01abc8c1e0972e1a0c2333e8c1cf9bee95..47263bcd5cf2b5dcfba2311f574bb8e04d5a5ac1 100644 (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
  * 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
- * applet's task is always created on the current thread.
+ * appctx_free(). <applet> is assigned as the applet, but it can be NULL. <thr>
+ * 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;