MINOR: applet: Add API to start applet on a thread subset

In the same way than for the tasks, the applets api was changed to be able
to start a new appctx on a thread subset. For now the feature is
disabled. Only appctx_new_here() is working. But it will be possible to
start an appctx on a specific thread or a subset via a mask.
diff --git a/include/haproxy/applet.h b/include/haproxy/applet.h
index f8d180c..0bba054 100644
--- a/include/haproxy/applet.h
+++ b/include/haproxy/applet.h
@@ -40,10 +40,25 @@
 void *applet_reserve_svcctx(struct appctx *appctx, size_t size);
 void appctx_shut(struct appctx *appctx);
 
-struct appctx *appctx_new(struct applet *applet, struct cs_endpoint *endp);
+struct appctx *appctx_new(struct applet *applet, struct cs_endpoint *endp, unsigned long thread_mask);
 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 cs_endpoint *endp, uint thr)
+{
+	return appctx_new(applet, endp, 1UL << thr);
+}
+
+static inline struct appctx *appctx_new_here(struct applet *applet, struct cs_endpoint *endp)
+{
+	return appctx_new(applet, endp, tid_bit);
+}
+
+static inline struct appctx *appctx_new_anywhere(struct applet *applet, struct cs_endpoint *endp)
+{
+	return appctx_new(applet, endp, MAX_THREADS_MASK);
+}
+
 /* Helper function to call .init applet callback function, if it exists. Returns 0
  * on success and -1 on error.
  */
diff --git a/src/applet.c b/src/applet.c
index e8b56c1..3c5ffb2 100644
--- a/src/applet.c
+++ b/src/applet.c
@@ -31,10 +31,13 @@
  * appctx_free(). <applet> is assigned as the applet, but it can be NULL. The
  * applet's task is always created on the current thread.
  */
-struct appctx *appctx_new(struct applet *applet, struct cs_endpoint *endp)
+struct appctx *appctx_new(struct applet *applet, struct cs_endpoint *endp, unsigned long thread_mask)
 {
 	struct appctx *appctx;
 
+	/* Disable the feature for now ! */
+	BUG_ON(thread_mask != tid_bit);
+
 	appctx = pool_zalloc(pool_head_appctx);
 	if (unlikely(!appctx))
 		goto fail_appctx;
@@ -53,7 +56,7 @@
 	}
 	appctx->endp = endp;
 
-	appctx->t = task_new_here();
+	appctx->t = task_new(thread_mask);
 	if (unlikely(!appctx->t))
 		goto fail_task;
 	appctx->t->process = task_run_applet;
diff --git a/src/conn_stream.c b/src/conn_stream.c
index a37b463..8bf9d52 100644
--- a/src/conn_stream.c
+++ b/src/conn_stream.c
@@ -476,7 +476,7 @@
 
 	DPRINTF(stderr, "registering handler %p for cs %p (was %p)\n", app, cs, cs_strm_task(cs));
 
-	appctx = appctx_new(app, cs->endp);
+	appctx = appctx_new_here(app, cs->endp);
 	if (!appctx)
 		return NULL;
 	cs_attach_applet(cs, appctx, appctx);
diff --git a/src/dns.c b/src/dns.c
index 839d613..13bc1d7 100644
--- a/src/dns.c
+++ b/src/dns.c
@@ -955,7 +955,7 @@
 {
 	struct appctx *appctx;
 
-	appctx = appctx_new(&dns_session_applet, NULL);
+	appctx = appctx_new_here(&dns_session_applet, NULL);
 	if (!appctx)
 		goto out_close;
 	appctx->svcctx = (void *)ds;
diff --git a/src/flt_spoe.c b/src/flt_spoe.c
index 99ef7d6..7d97fed 100644
--- a/src/flt_spoe.c
+++ b/src/flt_spoe.c
@@ -2053,7 +2053,7 @@
 	LIST_INIT(&spoe_appctx->waiting_queue);
 
 
-	if ((appctx = appctx_new(&spoe_applet, NULL)) == NULL)
+	if ((appctx = appctx_new_here(&spoe_applet, NULL)) == NULL)
 		goto out_free_spoe_appctx;
 
 	appctx->svcctx = spoe_appctx;
diff --git a/src/hlua.c b/src/hlua.c
index 4fb5a62..470a675 100644
--- a/src/hlua.c
+++ b/src/hlua.c
@@ -2999,7 +2999,7 @@
 	lua_setmetatable(L, -2);
 
 	/* Create the applet context */
-	appctx = appctx_new(&update_applet, NULL);
+	appctx = appctx_new_here(&update_applet, NULL);
 	if (!appctx) {
 		hlua_pusherror(L, "socket: out of memory");
 		goto out_fail_conf;
diff --git a/src/http_client.c b/src/http_client.c
index ac134ad..53086a3 100644
--- a/src/http_client.c
+++ b/src/http_client.c
@@ -538,7 +538,7 @@
 
 	/* The HTTP client will be created in the same thread as the caller,
 	 * avoiding threading issues */
-	appctx = appctx_new(applet, NULL);
+	appctx = appctx_new_here(applet, NULL);
 	if (!appctx)
 		goto out;
 	appctx->svcctx = hc;
diff --git a/src/peers.c b/src/peers.c
index eb69155..0e48004 100644
--- a/src/peers.c
+++ b/src/peers.c
@@ -3199,7 +3199,7 @@
 	peer->statuscode = PEER_SESS_SC_CONNECTCODE;
 	peer->last_hdshk = now_ms;
 
-	appctx = appctx_new(&peer_applet, NULL);
+	appctx = appctx_new_here(&peer_applet, NULL);
 	if (!appctx)
 		goto out_close;
 	appctx->svcctx = (void *)peer;
diff --git a/src/sink.c b/src/sink.c
index 21b590e..a8635d1 100644
--- a/src/sink.c
+++ b/src/sink.c
@@ -673,7 +673,7 @@
 	if (sft->srv->log_proto == SRV_LOG_PROTO_OCTET_COUNTING)
 		applet = &sink_forward_oc_applet;
 
-	appctx = appctx_new(applet, NULL);
+	appctx = appctx_new_here(applet, NULL);
 	if (!appctx)
 		goto out_close;
 	appctx->svcctx = (void *)sft;