diff --git a/include/proto/applet.h b/include/proto/applet.h index 81c20e11a..5a503b43c 100644 --- a/include/proto/applet.h +++ b/include/proto/applet.h @@ -29,6 +29,9 @@ #include #include +extern unsigned int nb_applets; +extern unsigned int applets_active_queue; + extern struct list applet_active_queue; void applet_run_active(); @@ -58,6 +61,7 @@ static inline struct appctx *appctx_new(struct applet *applet) appctx->applet = applet; appctx_init(appctx); LIST_INIT(&appctx->runq); + nb_applets++; } return appctx; } @@ -67,16 +71,21 @@ static inline struct appctx *appctx_new(struct applet *applet) */ static inline void appctx_free(struct appctx *appctx) { - if (!LIST_ISEMPTY(&appctx->runq)) + if (!LIST_ISEMPTY(&appctx->runq)) { LIST_DEL(&appctx->runq); + applets_active_queue--; + } pool_free2(pool2_connection, appctx); + nb_applets--; } /* wakes up an applet when conditions have changed */ static inline void appctx_wakeup(struct appctx *appctx) { - if (LIST_ISEMPTY(&appctx->runq)) + if (LIST_ISEMPTY(&appctx->runq)) { LIST_ADDQ(&applet_active_queue, &appctx->runq); + applets_active_queue++; + } } /* removes an applet from the list of active applets */ @@ -85,6 +94,7 @@ static inline void appctx_pause(struct appctx *appctx) if (!LIST_ISEMPTY(&appctx->runq)) { LIST_DEL(&appctx->runq); LIST_INIT(&appctx->runq); + applets_active_queue--; } } diff --git a/src/applet.c b/src/applet.c index bc8972e67..ad40e1f9f 100644 --- a/src/applet.c +++ b/src/applet.c @@ -19,8 +19,11 @@ #include #include +unsigned int nb_applets = 0; +unsigned int applets_active_queue = 0; + struct list applet_active_queue = LIST_HEAD_INIT(applet_active_queue); -struct list applet_run_queue = LIST_HEAD_INIT(applet_run_queue); +struct list applet_cur_queue = LIST_HEAD_INIT(applet_cur_queue); void applet_run_active() { @@ -31,18 +34,18 @@ void applet_run_active() return; /* move active queue to run queue */ - applet_active_queue.n->p = &applet_run_queue; - applet_active_queue.p->n = &applet_run_queue; + applet_active_queue.n->p = &applet_cur_queue; + applet_active_queue.p->n = &applet_cur_queue; - applet_run_queue = applet_active_queue; + applet_cur_queue = applet_active_queue; LIST_INIT(&applet_active_queue); /* The list is only scanned from the head. This guarantees that if any * applet removes another one, there is no side effect while walking * through the list. */ - while (!LIST_ISEMPTY(&applet_run_queue)) { - curr = LIST_ELEM(applet_run_queue.n, typeof(curr), runq); + while (!LIST_ISEMPTY(&applet_cur_queue)) { + curr = LIST_ELEM(applet_cur_queue.n, typeof(curr), runq); si = curr->owner; /* now we'll need a buffer */ @@ -63,7 +66,7 @@ void applet_run_active() curr->applet->fct(curr); si_applet_wake_cb(si); - if (applet_run_queue.n == &curr->runq) { + if (applet_cur_queue.n == &curr->runq) { /* curr was left in the list, move it back to the active list */ LIST_DEL(&curr->runq); LIST_ADDQ(&applet_active_queue, &curr->runq); diff --git a/src/haproxy.c b/src/haproxy.c index 5d7d410bc..b403ba1c1 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -1730,7 +1730,7 @@ void run_poll_loop() break; /* expire immediately if events are pending */ - if (fd_cache_num || run_queue || signal_queue_len || !LIST_ISEMPTY(&applet_active_queue)) + if (fd_cache_num || run_queue || signal_queue_len || applets_active_queue) next = now_ms; /* The poller will ensure it returns around */