MINOR: applet: Count number of (active) applets

As for tasks, 2 counters has been added to track :
  * the total number of applets : nb_applets
  * the number of active applets : applets_active_queue

[wt: needed for next fixes, to backport to 1.7 and 1.6]
This commit is contained in:
Christopher Faulet 2016-12-06 09:13:22 +01:00 committed by Willy Tarreau
parent 90b5abe46e
commit 1cbe74cd83
3 changed files with 23 additions and 10 deletions

View File

@ -29,6 +29,9 @@
#include <types/applet.h>
#include <proto/connection.h>
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--;
}
}

View File

@ -19,8 +19,11 @@
#include <proto/stream.h>
#include <proto/stream_interface.h>
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);

View File

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