2
0
Fork 0

[lua] Use recursive lock for global lua lock

personal/stbuehler/wip
Stefan Bühler 2012-12-06 15:43:11 +01:00
parent 178e7c898f
commit 01abf704a3
4 changed files with 12 additions and 7 deletions

View File

@ -4,8 +4,8 @@
#include <lighttpd/base.h>
#include <lua.h>
#define li_lua_lock(srv) g_mutex_lock((srv)->lualock);
#define li_lua_unlock(srv) g_mutex_unlock((srv)->lualock);
#define li_lua_lock(srv) g_static_rec_mutex_lock(&(srv)->lualock);
#define li_lua_unlock(srv) g_static_rec_mutex_unlock(&(srv)->lualock);
LI_API void li_lua_init_chunk_mt(lua_State *L);
LI_API liChunk* li_lua_get_chunk(lua_State *L, int ndx);

View File

@ -66,7 +66,7 @@ struct liServer {
liServerState state_wait_for;
ev_async state_ready_watcher;
GMutex *lualock;
GStaticRecMutex lualock;
struct lua_State *L; /** NULL if compiled without Lua */
liWorker *main_worker;

View File

@ -136,8 +136,13 @@ static liHandlerResult lua_action_cleanup(liVRequest *vr, gpointer param, gpoint
static void lua_action_free(liServer *srv, gpointer param) {
lua_action_param *par = param;
lua_State *L = par->L;
gboolean dolock = (L == srv->L);
lua_State *L;
gboolean dolock;
if (!param) return;
L = par->L;
dolock = (L == srv->L);
if (dolock) li_lua_lock(srv);
luaL_unref(L, LUA_REGISTRYINDEX, par->func_ref);

View File

@ -110,7 +110,7 @@ liServer* li_server_new(const gchar *module_dir, gboolean module_resident) {
luaL_openlibs(srv->L);
li_lua_init(srv->L, srv, NULL);
srv->lualock = g_mutex_new();
g_static_rec_mutex_free(&srv->lualock);
#else
srv->L = NULL;
#endif
@ -216,7 +216,7 @@ void li_server_free(liServer* srv) {
#ifdef HAVE_LUA_H
lua_close(srv->L);
srv->L = NULL;
g_mutex_free(srv->lualock);
g_static_rec_mutex_free(&srv->lualock);
#endif
/* free throttle pools */