diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-11-18 16:01:05 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-11-18 16:01:05 +0000 |
commit | aef1cac108507fcefba54694f46c4f2e8069c31d (patch) | |
tree | 5944bb32de8f4ded1cc972bf101f8846338418f2 /src/libserver | |
parent | 9b31d260b9bee44456fd2f37eee6c4ba2c8aba60 (diff) | |
download | rspamd-aef1cac108507fcefba54694f46c4f2e8069c31d.tar.gz rspamd-aef1cac108507fcefba54694f46c4f2e8069c31d.zip |
Implement refcounting for configuration
Diffstat (limited to 'src/libserver')
-rw-r--r-- | src/libserver/cfg_file.h | 2 | ||||
-rw-r--r-- | src/libserver/cfg_utils.c | 2 | ||||
-rw-r--r-- | src/libserver/task.c | 34 | ||||
-rw-r--r-- | src/libserver/task.h | 7 | ||||
-rw-r--r-- | src/libserver/worker_util.h | 1 |
5 files changed, 16 insertions, 30 deletions
diff --git a/src/libserver/cfg_file.h b/src/libserver/cfg_file.h index a2ec19034..96fc56d52 100644 --- a/src/libserver/cfg_file.h +++ b/src/libserver/cfg_file.h @@ -341,7 +341,7 @@ gboolean rspamd_parse_bind_line (struct rspamd_config *cfg, * Init default values * @param cfg config file */ -struct rspamd_config * rspamd_config_defaults (void); +struct rspamd_config *rspamd_config_new (void); /** * Free memory used by config structure diff --git a/src/libserver/cfg_utils.c b/src/libserver/cfg_utils.c index 4146d51cb..23de0bef2 100644 --- a/src/libserver/cfg_utils.c +++ b/src/libserver/cfg_utils.c @@ -145,7 +145,7 @@ rspamd_parse_bind_line (struct rspamd_config *cfg, } struct rspamd_config * -rspamd_config_defaults (void) +rspamd_config_new (void) { struct rspamd_config *cfg; diff --git a/src/libserver/task.c b/src/libserver/task.c index f89ca4097..c4ae1762c 100644 --- a/src/libserver/task.c +++ b/src/libserver/task.c @@ -42,19 +42,19 @@ rspamd_task_quark (void) * Create new task */ struct rspamd_task * -rspamd_task_new (struct rspamd_worker *worker) +rspamd_task_new (struct rspamd_worker *worker, struct rspamd_config *cfg) { struct rspamd_task *new_task; - new_task = g_slice_alloc0 (sizeof (struct rspamd_task)); + g_assert (cfg != NULL); + new_task = g_slice_alloc0 (sizeof (struct rspamd_task)); new_task->worker = worker; + new_task->cfg = cfg; + REF_RETAIN (cfg); - if (worker) { - new_task->cfg = worker->srv->cfg; - if (new_task->cfg->check_all_filters) { - new_task->flags |= RSPAMD_TASK_FLAG_PASS_ALL; - } + if (cfg->check_all_filters) { + new_task->flags |= RSPAMD_TASK_FLAG_PASS_ALL; } gettimeofday (&new_task->tv, NULL); @@ -169,7 +169,7 @@ rspamd_task_restore (void *arg) * Free all structures of worker_task */ void -rspamd_task_free (struct rspamd_task *task, gboolean is_soft) +rspamd_task_free (struct rspamd_task *task) { struct mime_part *p; struct mime_text_part *tp; @@ -229,27 +229,13 @@ rspamd_task_free (struct rspamd_task *task, gboolean is_soft) event_del (&task->timeout_ev); } + REF_RELEASE (task->cfg); + rspamd_mempool_delete (task->task_pool); g_slice_free1 (sizeof (struct rspamd_task), task); } } -void -rspamd_task_free_hard (gpointer ud) -{ - struct rspamd_task *task = ud; - - rspamd_task_free (task, FALSE); -} - -void -rspamd_task_free_soft (gpointer ud) -{ - struct rspamd_task *task = ud; - - rspamd_task_free (task, FALSE); -} - static void rspamd_task_unmapper (gpointer ud) { diff --git a/src/libserver/task.h b/src/libserver/task.h index 8a9e913a4..b29bcebf6 100644 --- a/src/libserver/task.h +++ b/src/libserver/task.h @@ -180,13 +180,12 @@ struct rspamd_task { /** * Construct new task for worker */ -struct rspamd_task * rspamd_task_new (struct rspamd_worker *worker); +struct rspamd_task * rspamd_task_new (struct rspamd_worker *worker, + struct rspamd_config *cfg); /** * Destroy task object and remove its IO dispatcher if it exists */ -void rspamd_task_free (struct rspamd_task *task, gboolean is_soft); -void rspamd_task_free_hard (gpointer ud); -void rspamd_task_free_soft (gpointer ud); +void rspamd_task_free (struct rspamd_task *task); /** * Called if session was restored inside fin callback diff --git a/src/libserver/worker_util.h b/src/libserver/worker_util.h index 3242d1669..21c86f92e 100644 --- a/src/libserver/worker_util.h +++ b/src/libserver/worker_util.h @@ -86,6 +86,7 @@ struct rspamd_controller_session { struct rspamd_task *task; struct rspamd_classifier_config *cl; rspamd_inet_addr_t *from_addr; + struct rspamd_config *cfg; gboolean is_spam; }; |