[lua] Use recursive lock for global lua lock

personal/stbuehler/wip
Stefan Bühler 10 years ago
parent 178e7c898f
commit 01abf704a3
  1. 4
      include/lighttpd/core_lua.h
  2. 2
      include/lighttpd/server.h
  3. 9
      src/main/actions_lua.c
  4. 4
      src/main/server.c

@ -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);

@ -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;

@ -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);

@ -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 */

Loading…
Cancel
Save