MEDIUM: applet: add basic support for an applet run queue
This will be needed so that we can schedule applets out of the streams.
For now nothing calls the queue yet.
diff --git a/Makefile b/Makefile
index 917f023..3c9ee24 100644
--- a/Makefile
+++ b/Makefile
@@ -703,7 +703,7 @@
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 \
diff --git a/include/proto/applet.h b/include/proto/applet.h
index fd458d4..4e43bbe 100644
--- a/include/proto/applet.h
+++ b/include/proto/applet.h
@@ -25,9 +25,12 @@
#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 @@
appctx->obj_type = OBJ_TYPE_APPCTX;
appctx->applet = applet;
appctx_init(appctx);
+ LIST_INIT(&appctx->runq);
}
return appctx;
}
@@ -60,9 +64,18 @@
*/
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 */
/*
diff --git a/include/types/applet.h b/include/types/applet.h
index 5e989f6..c2db0ec 100644
--- a/include/types/applet.h
+++ b/include/types/applet.h
@@ -40,6 +40,7 @@
/* 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
index 0000000..ca3ead1
--- /dev/null
+++ b/src/applet.c
@@ -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);