diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2012-08-22 21:41:48 +0400 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2012-08-22 21:41:48 +0400 |
commit | b90267a71cc8cdc8b38675322ef9fa7a9cb5468c (patch) | |
tree | 3bff8af523d19ec9cff93134b067fc404795000d /src/filter.c | |
parent | ed224e6a3530f54b5993e39066a8397d54e9517e (diff) | |
download | rspamd-b90267a71cc8cdc8b38675322ef9fa7a9cb5468c.tar.gz rspamd-b90267a71cc8cdc8b38675322ef9fa7a9cb5468c.zip |
* Rework thread pools locking logic to avoid global lua mutex usage.
Fixed several memory leaks with modern glib.
Fixed memory leak in dkim code.
Fixed a problem with static global variables in shared libraries.
Diffstat (limited to 'src/filter.c')
-rw-r--r-- | src/filter.c | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/src/filter.c b/src/filter.c index d7d2a0c15..7593046ca 100644 --- a/src/filter.c +++ b/src/filter.c @@ -585,10 +585,16 @@ make_composites (struct worker_task *task) g_hash_table_foreach (task->results, composites_metric_callback, task); } +struct classifiers_cbdata { + struct worker_task *task; + struct lua_locked_state *nL; +}; + static void classifiers_callback (gpointer value, void *arg) { - struct worker_task *task = arg; + struct classifiers_cbdata *cbdata = arg; + struct worker_task *task; struct classifier_config *cl = value; struct classifier_ctx *ctx; struct mime_text_part *text_part, *p1, *p2; @@ -600,6 +606,8 @@ classifiers_callback (gpointer value, void *arg) gint *dist = NULL, diff; gboolean is_twopart = FALSE; + task = cbdata->task; + if ((header = g_hash_table_lookup (cl->opts, "header")) != NULL) { cur = message_get_header (task->task_pool, task->message, header, FALSE); if (cur) { @@ -675,7 +683,15 @@ classifiers_callback (gpointer value, void *arg) /* Take care of subject */ tokenize_subject (task, &tokens); - cl->classifier->classify_func (ctx, task->worker->srv->statfile_pool, tokens, task); + if (cbdata->nL != NULL) { + rspamd_mutex_lock (cbdata->nL->m); + cl->classifier->classify_func (ctx, task->worker->srv->statfile_pool, tokens, task, cbdata->nL->L); + rspamd_mutex_unlock (cbdata->nL->m); + } + else { + /* Non-threaded case */ + cl->classifier->classify_func (ctx, task->worker->srv->statfile_pool, tokens, task, task->cfg->lua_state); + } /* Autolearning */ cur = g_list_first (cl->statfiles); @@ -695,6 +711,7 @@ classifiers_callback (gpointer value, void *arg) void process_statfiles (struct worker_task *task) { + struct classifiers_cbdata cbdata; if (task->is_skipped) { return; @@ -704,8 +721,9 @@ process_statfiles (struct worker_task *task) task->tokens = g_hash_table_new (g_direct_hash, g_direct_equal); memory_pool_add_destructor (task->task_pool, (pool_destruct_func)g_hash_table_unref, task->tokens); } - - g_list_foreach (task->cfg->classifiers, classifiers_callback, task); + cbdata.task = task; + cbdata.nL = NULL; + g_list_foreach (task->cfg->classifiers, classifiers_callback, &cbdata); /* Process results */ make_composites (task); @@ -715,6 +733,8 @@ void process_statfiles_threaded (gpointer data, gpointer user_data) { struct worker_task *task = (struct worker_task *)data; + struct lua_locked_state *nL = user_data; + struct classifiers_cbdata cbdata; if (task->is_skipped) { return; @@ -725,7 +745,9 @@ process_statfiles_threaded (gpointer data, gpointer user_data) memory_pool_add_destructor (task->task_pool, (pool_destruct_func)g_hash_table_unref, task->tokens); } - g_list_foreach (task->cfg->classifiers, classifiers_callback, task); + cbdata.task = task; + cbdata.nL = nL; + g_list_foreach (task->cfg->classifiers, classifiers_callback, &cbdata); remove_async_thread (task->s); } @@ -1054,7 +1076,7 @@ learn_task_spam (struct classifier_config *cl, struct worker_task *task, gboolea /* Learn */ if (!cl->classifier->learn_spam_func ( cls_ctx, task->worker->srv->statfile_pool, - tokens, task, is_spam, err)) { + tokens, task, is_spam, task->cfg->lua_state, err)) { if (*err) { msg_info ("learn failed for message <%s>, learn error: %s", task->message_id, (*err)->message); return FALSE; |