]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: applet: Remove appctx state field to only used the flags
authorChristopher Faulet <cfaulet@haproxy.com>
Mon, 15 Jan 2024 17:42:39 +0000 (18:42 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 7 Feb 2024 14:03:46 +0000 (15:03 +0100)
The appctx state was never really used as a state. It is only used to know
when an applet should be freed on the next wakeup. This can be converted to
a flag and the state can be removed. This is what this patch does.

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

index 9c70469c2ad8aec80b150c2faeb6bd6f975d3cf4..bd3bf68ca0fffdcba746de72aedcf8bbd29583f5 100644 (file)
@@ -31,7 +31,6 @@
 #include <haproxy/xref-t.h>
 
 /* flags for appctx->state */
-#define APPLET_WANT_DIE      0x01  /* applet was running and requested to die */
 
 /* Room for per-command context (mostly CLI commands but not only) */
 #define APPLET_MAX_SVCCTX 88
@@ -45,6 +44,7 @@
 #define APPCTX_FL_EOS            0x00000020
 #define APPCTX_FL_ERR_PENDING    0x00000040
 #define APPCTX_FL_ERROR          0x00000080
+#define APPCTX_FL_WANT_DIE       0x00000100  /* applet was running and requested to die */
 
 struct appctx;
 struct proxy;
@@ -71,7 +71,6 @@ struct applet {
 struct appctx {
        enum obj_type obj_type;    /* OBJ_TYPE_APPCTX */
        /* 3 unused bytes here */
-       unsigned short state;      /* Internal appctx state */
        unsigned int st0;          /* CLI state for stats, session state for peers */
        unsigned int st1;          /* prompt/payload (bitwise OR of APPCTX_CLI_ST1_*) for stats, session error for peers */
 
index 27c1f7f4042ebb08afa9a101bbb66061c55a05fe..77f69346a93a0d34a12ef2e848df090230321a02 100644 (file)
@@ -138,9 +138,9 @@ static void applet_trace(enum trace_level level, uint64_t mask, const struct tra
        if (src->verbosity == STRM_VERB_CLEAN)
                return;
 
-       chunk_appendf(&trace_buf, " appctx=%p .t=%p .t.exp=%d .state=%d .st0=%d .st1=%d",
+       chunk_appendf(&trace_buf, " appctx=%p .t=%p .t.exp=%d .flags=0x%x .st0=%d .st1=%d",
                      appctx, appctx->t, tick_isset(appctx->t->expire) ? TICKS_TO_MS(appctx->t->expire - now_ms) : TICK_ETERNITY,
-                     appctx->state, appctx->st0, appctx->st1);
+                     appctx->flags, appctx->st0, appctx->st1);
 
        if (!sc || src->verbosity == STRM_VERB_MINIMAL)
                return;
@@ -350,7 +350,7 @@ void appctx_free(struct appctx *appctx)
                /* if it's running, or about to run, defer the freeing
                 * until the callback is called.
                 */
-               appctx->state |= APPLET_WANT_DIE;
+               applet_fl_set(appctx, APPCTX_FL_WANT_DIE);
                task_wakeup(appctx->t, TASK_WOKEN_OTHER);
                TRACE_DEVEL("Cannot release APPCTX now, wake it up", APPLET_EV_FREE, appctx);
        }
@@ -589,7 +589,7 @@ struct task *task_run_applet(struct task *t, void *context, unsigned int state)
 
        TRACE_ENTER(APPLET_EV_PROCESS, app);
 
-       if (app->state & APPLET_WANT_DIE) {
+       if (applet_fl_test(app, APPCTX_FL_WANT_DIE)) {
                TRACE_DEVEL("APPCTX want die, release it", APPLET_EV_FREE, app);
                __appctx_free(app);
                return NULL;
@@ -660,6 +660,7 @@ struct task *task_run_applet(struct task *t, void *context, unsigned int state)
                sc_ep_report_read_activity(sc);
        }
 
+       /* TODO: May be move in appctx_rcv_buf or sc_applet_process ? */
        if (sc_waiting_room(sc) && (sc->flags & SC_FL_ABRT_DONE)) {
                sc_ep_set(sc, SE_FL_EOS|SE_FL_ERROR);
        }
@@ -698,7 +699,7 @@ struct task *task_process_applet(struct task *t, void *context, unsigned int sta
 
        TRACE_ENTER(APPLET_EV_PROCESS, app);
 
-       if (app->state & APPLET_WANT_DIE) {
+       if (applet_fl_test(app, APPCTX_FL_WANT_DIE)) {
                TRACE_DEVEL("APPCTX want die, release it", APPLET_EV_FREE, app);
                __appctx_free(app);
                return NULL;