diff options
author | Mikhail Galanin <mgalanin@mimecast.com> | 2018-08-14 14:36:05 +0100 |
---|---|---|
committer | Mikhail Galanin <mgalanin@mimecast.com> | 2018-08-14 14:36:05 +0100 |
commit | 9926cc68e2c143be8a05b91e28ba8830abfea04a (patch) | |
tree | ee8997d9488c9dd67a5a77789377cbd517275d56 /src/lua/lua_config.c | |
parent | f9d4b50321057009489dbc673b108e6433f4ae38 (diff) | |
download | rspamd-9926cc68e2c143be8a05b91e28ba8830abfea04a.tar.gz rspamd-9926cc68e2c143be8a05b91e28ba8830abfea04a.zip |
[Minor] Use coroutine model in dns resolver API
Diffstat (limited to 'src/lua/lua_config.c')
-rw-r--r-- | src/lua/lua_config.c | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c index 3a38d437b..31deed5c5 100644 --- a/src/lua/lua_config.c +++ b/src/lua/lua_config.c @@ -1206,6 +1206,9 @@ lua_metric_symbol_callback (struct rspamd_task *task, gpointer ud) struct thread_entry *thread_entry = lua_thread_pool_get (task->cfg->lua_thread_pool); cd->thread_entry = thread_entry; + g_assert(thread_entry->cd == NULL); + thread_entry->cd = cd; + lua_State *thread = thread_entry->lua_state; cd->stack_level = lua_gettop (cd->L); @@ -1232,6 +1235,29 @@ lua_metric_symbol_callback (struct rspamd_task *task, gpointer ud) } } +gint +lua_yield_thread (struct thread_entry *thread_entry, gint nresults) +{ + g_assert (thread_entry->cd != NULL); + + return lua_yield (thread_entry->lua_state, nresults); +} + +void +lua_resume_thread (struct rspamd_task *task, struct thread_entry *thread_entry, gint narg) +{ + g_assert (thread_entry->cd != NULL); + + gint ret; + + lua_thread_pool_set_running_entry (task->cfg->lua_thread_pool, thread_entry); + ret = lua_resume (thread_entry->lua_state, narg); + + if (ret != LUA_YIELD) { + lua_metric_symbol_callback_return (task, thread_entry->cd, ret); + } +} + static void lua_metric_symbol_callback_return (struct rspamd_task *task, gpointer ud, gint ret) { @@ -1337,7 +1363,7 @@ lua_metric_symbol_callback_return (struct rspamd_task *task, gpointer ud, gint r g_assert (lua_gettop (thread) == cd->stack_level); /* we properly cleaned up the stack */ - lua_thread_pool_return(task->cfg->lua_thread_pool, cd->thread_entry); + lua_thread_pool_return (task->cfg->lua_thread_pool, cd->thread_entry); } cd->thread_entry = NULL; |