diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-01-06 16:19:48 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-01-06 16:19:48 +0000 |
commit | b9ed71b1badf535aa989f056da56ccf8ed187b76 (patch) | |
tree | 7a398efed96ce3ffbd8a0c8f873340c53a292e30 /src | |
parent | 4b0615f1d6983ef1c9e3c292c4608d3f37df2172 (diff) | |
download | rspamd-b9ed71b1badf535aa989f056da56ccf8ed187b76.tar.gz rspamd-b9ed71b1badf535aa989f056da56ccf8ed187b76.zip |
Add preliminary support of async events in libstat
Diffstat (limited to 'src')
-rw-r--r-- | src/libstat/stat_config.c | 16 | ||||
-rw-r--r-- | src/libstat/stat_internal.h | 8 |
2 files changed, 24 insertions, 0 deletions
diff --git a/src/libstat/stat_config.c b/src/libstat/stat_config.c index 1646ce3b7..ac4d70fc8 100644 --- a/src/libstat/stat_config.c +++ b/src/libstat/stat_config.c @@ -110,6 +110,7 @@ rspamd_stat_init (struct rspamd_config *cfg, struct event_base *ev_base) stat_ctx->cfg = cfg; stat_ctx->statfiles = g_ptr_array_new (); stat_ctx->classifiers = g_ptr_array_new (); + stat_ctx->async_elts = g_queue_new (); stat_ctx->ev_base = ev_base; REF_RETAIN (stat_ctx->cfg); @@ -197,6 +198,8 @@ rspamd_stat_close (void) struct rspamd_classifier *cl; struct rspamd_statfile *st; struct rspamd_stat_ctx *st_ctx; + struct rspamd_stat_async_elt *aelt; + GList *cur; guint i, j; gint id; @@ -218,6 +221,19 @@ rspamd_stat_close (void) g_slice_free1 (sizeof (*cl), cl); } + cur = st_ctx->async_elts->head; + + while (cur) { + aelt = cur->data; + + if (aelt->cleanup) { + aelt->cleanup (aelt, aelt->ud); + } + + cur = g_list_next (cur); + } + + g_queue_free (stat_ctx->async_elts); g_ptr_array_free (st_ctx->statfiles, TRUE); g_ptr_array_free (st_ctx->classifiers, TRUE); REF_RELEASE (stat_ctx->cfg); diff --git a/src/libstat/stat_internal.h b/src/libstat/stat_internal.h index 7e5804b8b..31257938d 100644 --- a/src/libstat/stat_internal.h +++ b/src/libstat/stat_internal.h @@ -65,6 +65,13 @@ typedef struct token_node_s { gdouble values[]; } rspamd_token_t; +struct rspamd_stat_async_elt { + void (*handler)(struct rspamd_stat_async_elt *elt, gpointer ud); + void (*cleanup)(struct rspamd_stat_async_elt *elt, gpointer ud); + struct event ev; + gpointer ud; +}; + struct rspamd_stat_ctx { /* Subroutines for all objects */ struct rspamd_stat_classifier *classifiers_subrs; @@ -79,6 +86,7 @@ struct rspamd_stat_ctx { /* Runtime configuration */ GPtrArray *statfiles; /* struct rspamd_statfile */ GPtrArray *classifiers; /* struct rspamd_classifier */ + GQueue *async_elts; /* struct rspamd_stat_async_elt */ struct rspamd_config *cfg; /* Global tokenizer */ struct rspamd_stat_tokenizer *tokenizer; |