aboutsummaryrefslogtreecommitdiffstats
path: root/src/classifiers/bayes.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2012-02-13 21:51:10 +0400
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2012-02-13 21:51:10 +0400
commita5b48a05a94d178c342bbad69a330addb518d148 (patch)
treeee7ab452cd4a98fdb7503e78cc52a3d4f66dd27e /src/classifiers/bayes.c
parent0d64c808b7310b6e233ec570649fbb281a3f2b13 (diff)
downloadrspamd-a5b48a05a94d178c342bbad69a330addb518d148.tar.gz
rspamd-a5b48a05a94d178c342bbad69a330addb518d148.zip
* More things to be thread-safe:
- pool allocator is now thread-safe - lua subsystem now holds lock to avoid lua stack corruption - events subsystem now using conditional variables to wait for async_threads - insert_result is thread-safe now
Diffstat (limited to 'src/classifiers/bayes.c')
-rw-r--r--src/classifiers/bayes.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/classifiers/bayes.c b/src/classifiers/bayes.c
index 265957bc9..281cc6292 100644
--- a/src/classifiers/bayes.c
+++ b/src/classifiers/bayes.c
@@ -165,6 +165,16 @@ bayes_classify_callback (gpointer key, gpointer value, gpointer data)
return FALSE;
}
+#if ((GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION <= 30))
+static void
+bayes_mutex_free (gpointer data)
+{
+ GMutex *mtx = data;
+
+ g_mutex_free (mtx);
+}
+#endif
+
struct classifier_ctx*
bayes_init (memory_pool_t *pool, struct classifier_config *cfg)
{
@@ -173,6 +183,13 @@ bayes_init (memory_pool_t *pool, struct classifier_config *cfg)
ctx->pool = pool;
ctx->cfg = cfg;
ctx->debug = FALSE;
+#if ((GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION <= 30))
+ ctx->mtx = g_mutex_new ();
+ memory_pool_add_destructor (pool, (pool_destruct_func) bayes_mutex_free, ctx->mtx);
+#else
+ ctx->mtx = memory_pool_alloc (pool, sizeof (GMutex));
+ g_mutex_init (ctx->mtx);
+#endif
return ctx;
}
@@ -205,6 +222,8 @@ bayes_classify (struct classifier_ctx* ctx, statfile_pool_t *pool, GTree *input,
}
}
+ /* Critical section as here can be lua callbacks calling */
+ g_mutex_lock (ctx->mtx);
cur = call_classifier_pre_callbacks (ctx->cfg, task, FALSE, FALSE);
if (cur) {
memory_pool_add_destructor (task->task_pool, (pool_destruct_func)g_list_free, cur);
@@ -212,6 +231,7 @@ bayes_classify (struct classifier_ctx* ctx, statfile_pool_t *pool, GTree *input,
else {
cur = ctx->cfg->statfiles;
}
+ g_mutex_unlock (ctx->mtx);
data.statfiles_num = g_list_length (cur);
data.statfiles = g_new0 (struct bayes_statfile_data, data.statfiles_num);