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.
This commit is contained in:
Willy Tarreau 2015-04-13 17:11:11 +02:00
parent d45b9f8991
commit 81f38d6f57
4 changed files with 36 additions and 1 deletions

View File

@ -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 \

View File

@ -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 @@ 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 */
/*

View 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 */

21
src/applet.c Normal file
View File

@ -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);