aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua/lua_session.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2012-08-22 21:41:48 +0400
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2012-08-22 21:41:48 +0400
commitb90267a71cc8cdc8b38675322ef9fa7a9cb5468c (patch)
tree3bff8af523d19ec9cff93134b067fc404795000d /src/lua/lua_session.c
parented224e6a3530f54b5993e39066a8397d54e9517e (diff)
downloadrspamd-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/lua/lua_session.c')
-rw-r--r--src/lua/lua_session.c36
1 files changed, 2 insertions, 34 deletions
diff --git a/src/lua/lua_session.c b/src/lua/lua_session.c
index a25363430..db8d0ef23 100644
--- a/src/lua/lua_session.c
+++ b/src/lua/lua_session.c
@@ -89,12 +89,7 @@ static gboolean
lua_session_finalizer (gpointer ud)
{
struct lua_session_udata *cbdata = ud;
- gboolean need_unlock = FALSE, res;
-
- /* Avoid LOR here as mutex can be acquired before in lua_call */
- if (g_mutex_trylock (lua_mtx)) {
- need_unlock = TRUE;
- }
+ gboolean res;
/* Call finalizer function */
lua_rawgeti (cbdata->L, LUA_REGISTRYINDEX, cbdata->cbref_fin);
@@ -104,9 +99,7 @@ lua_session_finalizer (gpointer ud)
res = lua_toboolean (cbdata->L, -1);
lua_pop (cbdata->L, 1);
luaL_unref (cbdata->L, LUA_REGISTRYINDEX, cbdata->cbref_fin);
- if (need_unlock) {
- g_mutex_unlock (lua_mtx);
- }
+
return res;
}
@@ -115,13 +108,8 @@ static void
lua_session_restore (gpointer ud)
{
struct lua_session_udata *cbdata = ud;
- gboolean need_unlock = FALSE;
if (cbdata->cbref_restore) {
- /* Avoid LOR here as mutex can be acquired before in lua_call */
- if (g_mutex_trylock (lua_mtx)) {
- need_unlock = TRUE;
- }
/* Call restorer function */
lua_rawgeti (cbdata->L, LUA_REGISTRYINDEX, cbdata->cbref_restore);
@@ -129,9 +117,6 @@ lua_session_restore (gpointer ud)
msg_info ("call to session restorer failed: %s", lua_tostring (cbdata->L, -1));
}
luaL_unref (cbdata->L, LUA_REGISTRYINDEX, cbdata->cbref_restore);
- if (need_unlock) {
- g_mutex_unlock (lua_mtx);
- }
}
}
@@ -139,13 +124,8 @@ static void
lua_session_cleanup (gpointer ud)
{
struct lua_session_udata *cbdata = ud;
- gboolean need_unlock = FALSE;
if (cbdata->cbref_cleanup) {
- /* Avoid LOR here as mutex can be acquired before in lua_call */
- if (g_mutex_trylock (lua_mtx)) {
- need_unlock = TRUE;
- }
/* Call restorer function */
lua_rawgeti (cbdata->L, LUA_REGISTRYINDEX, cbdata->cbref_cleanup);
@@ -153,9 +133,6 @@ lua_session_cleanup (gpointer ud)
msg_info ("call to session cleanup failed: %s", lua_tostring (cbdata->L, -1));
}
luaL_unref (cbdata->L, LUA_REGISTRYINDEX, cbdata->cbref_cleanup);
- if (need_unlock) {
- g_mutex_unlock (lua_mtx);
- }
}
}
@@ -238,23 +215,14 @@ static void
lua_event_fin (gpointer ud)
{
struct lua_event_udata *cbdata = ud;
- gboolean need_unlock = FALSE;
if (cbdata->cbref) {
- /* Avoid LOR here as mutex can be acquired before in lua_call */
- if (g_mutex_trylock (lua_mtx)) {
- need_unlock = TRUE;
- }
-
/* Call restorer function */
lua_rawgeti (cbdata->L, LUA_REGISTRYINDEX, cbdata->cbref);
if (lua_pcall (cbdata->L, 0, 0, 0) != 0) {
msg_info ("call to event finalizer failed: %s", lua_tostring (cbdata->L, -1));
}
luaL_unref (cbdata->L, LUA_REGISTRYINDEX, cbdata->cbref);
- if (need_unlock) {
- g_mutex_unlock (lua_mtx);
- }
}
}