]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: applet: add basic support for an applet run queue
authorWilly Tarreau <w@1wt.eu>
Mon, 13 Apr 2015 15:11:11 +0000 (17:11 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 23 Apr 2015 15:56:16 +0000 (17:56 +0200)
This will be needed so that we can schedule applets out of the streams.
For now nothing calls the queue yet.

Makefile
include/proto/applet.h
include/types/applet.h
src/applet.c [new file with mode: 0644]

index 917f023f6644a29050f56fa65684d5e3f4ff4550..3c9ee24f5a01fa927552c7ab9f66a0b0df0d4743 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -703,7 +703,7 @@ OBJS = src/haproxy.o src/sessionhash.o src/base64.o src/protocol.o \
        src/arg.o src/stick_table.o src/proto_uxst.o src/connection.o \
        src/proto_http.o src/raw_sock.o src/appsession.o src/backend.o \
        src/lb_chash.o src/lb_fwlc.o src/lb_fwrr.o src/lb_map.o src/lb_fas.o \
-       src/stream_interface.o src/dumpstats.o src/proto_tcp.o \
+       src/stream_interface.o src/dumpstats.o src/proto_tcp.o src/applet.o \
        src/session.o src/stream.o src/hdr_idx.o src/ev_select.o src/signal.o \
        src/acl.o src/sample.o src/memory.o src/freq_ctr.o src/auth.o \
        src/compression.o src/payload.o src/hash.o src/pattern.o src/map.o \
index fd458d492f1b10b64a0fd091d5c3c5a5b9eca70e..4e43bbe5b298dfed9111c166a7caf335b57cd8b8 100644 (file)
 #include <stdlib.h>
 
 #include <common/config.h>
+#include <common/mini-clist.h>
 #include <types/applet.h>
 #include <proto/connection.h>
 
+extern struct list applet_runq;
+
 /* Initializes all required fields for a new appctx. Note that it does the
  * minimum acceptable initialization for an appctx. This means only the
  * 3 integer states st0, st1, st2 are zeroed.
@@ -51,6 +54,7 @@ static inline struct appctx *appctx_new(struct applet *applet)
                appctx->obj_type = OBJ_TYPE_APPCTX;
                appctx->applet = applet;
                appctx_init(appctx);
+               LIST_INIT(&appctx->runq);
        }
        return appctx;
 }
@@ -60,9 +64,18 @@ static inline struct appctx *appctx_new(struct applet *applet)
  */
 static inline void appctx_free(struct appctx *appctx)
 {
+       if (!LIST_ISEMPTY(&appctx->runq))
+               LIST_DEL(&appctx->runq);
        pool_free2(pool2_connection, appctx);
 }
 
+/* wakes up an applet when conditions have changed */
+static inline void appctx_wakeup(struct appctx *appctx)
+{
+       if (LIST_ISEMPTY(&appctx->runq))
+               LIST_ADDQ(&applet_runq, &appctx->runq);
+}
+
 #endif /* _PROTO_APPLET_H */
 
 /*
index 5e989f6bc03f98ddaeba521295e58d6b736c0b23..c2db0ec3eac4a9b060a5d7fd23fb473533f7fb40 100644 (file)
@@ -40,6 +40,7 @@ struct applet {
 
 /* Context of a running applet. */
 struct appctx {
+       struct list runq;          /* chaining in the applet run queue */
        enum obj_type obj_type;    /* OBJ_TYPE_APPCTX */
        /* 3 unused bytes here */
        unsigned int st0;          /* CLI state for stats, session state for peers */
diff --git a/src/applet.c b/src/applet.c
new file mode 100644 (file)
index 0000000..ca3ead1
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+ * Functions managing applets
+ *
+ * Copyright 2000-2015 Willy Tarreau <w@1wt.eu>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <common/config.h>
+#include <common/mini-clist.h>
+#include <proto/applet.h>
+
+
+struct list applet_runq = LIST_HEAD_INIT(applet_runq);