mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-03-31 23:58:16 +00:00
MEDIUM: applet: implement a run queue for active appctx
The new function is called for each round of polling in order to call any active appctx. For now we pick the stream interface from the appctx's owner. At the moment there's no appctx queued yet, but we have everything needed to queue them and remove them.
This commit is contained in:
parent
81f38d6f57
commit
3c595ac3ad
@ -31,6 +31,8 @@
|
||||
|
||||
extern struct list applet_runq;
|
||||
|
||||
void applet_run_active();
|
||||
|
||||
/* 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.
|
||||
@ -76,6 +78,15 @@ static inline void appctx_wakeup(struct appctx *appctx)
|
||||
LIST_ADDQ(&applet_runq, &appctx->runq);
|
||||
}
|
||||
|
||||
/* removes an applet from the list of active applets */
|
||||
static inline void appctx_pause(struct appctx *appctx)
|
||||
{
|
||||
if (!LIST_ISEMPTY(&appctx->runq)) {
|
||||
LIST_DEL(&appctx->runq);
|
||||
LIST_INIT(&appctx->runq);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* _PROTO_APPLET_H */
|
||||
|
||||
/*
|
||||
|
24
src/applet.c
24
src/applet.c
@ -16,6 +16,28 @@
|
||||
#include <common/config.h>
|
||||
#include <common/mini-clist.h>
|
||||
#include <proto/applet.h>
|
||||
|
||||
#include <proto/stream.h>
|
||||
#include <proto/stream_interface.h>
|
||||
|
||||
struct list applet_runq = LIST_HEAD_INIT(applet_runq);
|
||||
|
||||
void applet_run_active()
|
||||
{
|
||||
struct appctx *curr, *back;
|
||||
struct stream_interface *si;
|
||||
|
||||
list_for_each_entry_safe(curr, back, &applet_runq, runq) {
|
||||
si = curr->owner;
|
||||
|
||||
/* now we'll need a buffer */
|
||||
if (!stream_alloc_recv_buffer(si_ic(si))) {
|
||||
si->flags |= SI_FL_WAIT_ROOM;
|
||||
LIST_DEL(&curr->runq);
|
||||
LIST_INIT(&curr->runq);
|
||||
continue;
|
||||
}
|
||||
|
||||
curr->applet->fct(curr);
|
||||
/* must not dereference curr nor si now because it might have been freed */
|
||||
}
|
||||
}
|
||||
|
@ -79,9 +79,10 @@
|
||||
#include <types/acl.h>
|
||||
#include <types/peers.h>
|
||||
|
||||
#include <proto/auth.h>
|
||||
#include <proto/acl.h>
|
||||
#include <proto/applet.h>
|
||||
#include <proto/arg.h>
|
||||
#include <proto/auth.h>
|
||||
#include <proto/backend.h>
|
||||
#include <proto/channel.h>
|
||||
#include <proto/checks.h>
|
||||
@ -1487,12 +1488,13 @@ void run_poll_loop()
|
||||
break;
|
||||
|
||||
/* expire immediately if events are pending */
|
||||
if (fd_cache_num || run_queue || signal_queue_len)
|
||||
if (fd_cache_num || run_queue || signal_queue_len || !LIST_ISEMPTY(&applet_runq))
|
||||
next = now_ms;
|
||||
|
||||
/* The poller will ensure it returns around <next> */
|
||||
cur_poller.poll(&cur_poller, next);
|
||||
fd_process_cached_events();
|
||||
applet_run_active();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user