From 81f38d6f5772a71eaa78d65d14c49c70f8fab6ab Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Mon, 13 Apr 2015 17:11:11 +0200 Subject: [PATCH] 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. --- Makefile | 2 +- include/proto/applet.h | 13 +++++++++++++ include/types/applet.h | 1 + src/applet.c | 21 +++++++++++++++++++++ 4 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 src/applet.c diff --git a/Makefile b/Makefile index 917f023f6..3c9ee24f5 100644 --- 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 \ diff --git a/include/proto/applet.h b/include/proto/applet.h index fd458d492..4e43bbe5b 100644 --- a/include/proto/applet.h +++ b/include/proto/applet.h @@ -25,9 +25,12 @@ #include #include +#include #include #include +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 */ /* diff --git a/include/types/applet.h b/include/types/applet.h index 5e989f6bc..c2db0ec3e 100644 --- a/include/types/applet.h +++ b/include/types/applet.h @@ -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 index 000000000..ca3ead1b3 --- /dev/null +++ b/src/applet.c @@ -0,0 +1,21 @@ +/* + * Functions managing applets + * + * Copyright 2000-2015 Willy Tarreau + * + * 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 +#include + +#include +#include +#include + + +struct list applet_runq = LIST_HEAD_INIT(applet_runq);