diff options
author | Mikhail Galanin <mgalanin@mimecast.com> | 2018-08-17 11:03:57 +0100 |
---|---|---|
committer | Mikhail Galanin <mgalanin@mimecast.com> | 2018-08-17 11:03:57 +0100 |
commit | 55afdd2905dd1d9f58982691a404c373e768d304 (patch) | |
tree | 3a1a6bfbae95ac1dc7a0720fd3da82e192ec970f /src/lua/lua_thread_pool.c | |
parent | f368a0a51e7073bdf244bf1a959fb5ccb0389b9b (diff) | |
download | rspamd-55afdd2905dd1d9f58982691a404c373e768d304.tar.gz rspamd-55afdd2905dd1d9f58982691a404c373e768d304.zip |
[Minor] Added callback helpers
Diffstat (limited to 'src/lua/lua_thread_pool.c')
-rw-r--r-- | src/lua/lua_thread_pool.c | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/src/lua/lua_thread_pool.c b/src/lua/lua_thread_pool.c index 865b41fce..979b31f6b 100644 --- a/src/lua/lua_thread_pool.c +++ b/src/lua/lua_thread_pool.c @@ -61,7 +61,7 @@ lua_thread_pool_free (struct lua_thread_pool *pool) } struct thread_entry * -lua_thread_pool_get(struct lua_thread_pool *pool) +lua_thread_pool_get (struct lua_thread_pool *pool) { gpointer cur; struct thread_entry *ent = NULL; @@ -81,7 +81,7 @@ lua_thread_pool_get(struct lua_thread_pool *pool) } void -lua_thread_pool_return(struct lua_thread_pool *pool, struct thread_entry *thread_entry) +lua_thread_pool_return (struct lua_thread_pool *pool, struct thread_entry *thread_entry) { g_assert (lua_status (thread_entry->lua_state) == 0); /* we can't return a running/yielded thread into the pool */ @@ -99,7 +99,7 @@ lua_thread_pool_return(struct lua_thread_pool *pool, struct thread_entry *thread } void -lua_thread_pool_terminate_entry(struct lua_thread_pool *pool, struct thread_entry *thread_entry) +lua_thread_pool_terminate_entry (struct lua_thread_pool *pool, struct thread_entry *thread_entry) { struct thread_entry *ent = NULL; @@ -119,13 +119,30 @@ lua_thread_pool_terminate_entry(struct lua_thread_pool *pool, struct thread_entr } struct thread_entry * -lua_thread_pool_get_running_entry(struct lua_thread_pool *pool) +lua_thread_pool_get_running_entry (struct lua_thread_pool *pool) { return pool->running_entry; } void -lua_thread_pool_set_running_entry(struct lua_thread_pool *pool, struct thread_entry *thread_entry) +lua_thread_pool_set_running_entry (struct lua_thread_pool *pool, struct thread_entry *thread_entry) { pool->running_entry = thread_entry; } + + +void +lua_thread_pool_prepare_callback (struct lua_thread_pool *pool, struct lua_callback_state *cbs) +{ + cbs->thread_pool = pool; + cbs->previous_thread = lua_thread_pool_get_running_entry (pool); + cbs->my_thread = lua_thread_pool_get (pool); + cbs->L = cbs->my_thread->lua_state; +} + +void +lua_thread_pool_restore_callback (struct lua_callback_state *cbs) +{ + lua_thread_pool_return (cbs->thread_pool, cbs->my_thread); + lua_thread_pool_set_running_entry (cbs->thread_pool, cbs->previous_thread); +} |