OPTIM/MEDIUM: lua: executes the garbage collector only when using cosocket
The garbage collector is a little bit heavy to run, and it was added
only for cosockets. This patch prevent useless executions when no
cosockets are used.
diff --git a/include/types/hlua.h b/include/types/hlua.h
index 43916d4..1bf2a75 100644
--- a/include/types/hlua.h
+++ b/include/types/hlua.h
@@ -25,6 +25,7 @@
#define HLUA_WAKERESWR 0x00000004
#define HLUA_WAKEREQWR 0x00000008
#define HLUA_EXIT 0x00000010
+#define HLUA_MUST_GC 0x00000020
enum hlua_exec {
HLUA_E_OK = 0,
diff --git a/src/hlua.c b/src/hlua.c
index b893a47..d205a38 100644
--- a/src/hlua.c
+++ b/src/hlua.c
@@ -923,9 +923,11 @@
* NOTE: maybe this action locks all the Lua threads untiml the en of
* the garbage collection.
*/
- lua_gc(lua->T, LUA_GCCOLLECT, 0);
- if (lua_status(lua->T) != LUA_OK)
- lua_gc(gL.T, LUA_GCCOLLECT, 0);
+ if (lua->flags & HLUA_MUST_GC) {
+ lua_gc(lua->T, LUA_GCCOLLECT, 0);
+ if (lua_status(lua->T) != LUA_OK)
+ lua_gc(gL.T, LUA_GCCOLLECT, 0);
+ }
lua->T = NULL;
}
@@ -1166,7 +1168,8 @@
}
/* This GC permits to destroy some object when a Lua timeout strikes. */
- if (ret != HLUA_E_AGAIN)
+ if (lua->flags & HLUA_MUST_GC &&
+ ret != HLUA_E_AGAIN)
lua_gc(lua->T, LUA_GCCOLLECT, 0);
switch (ret) {
@@ -2253,6 +2256,8 @@
si_applet_cant_put(&socket->s->si[0]);
appctx_wakeup(appctx);
+ hlua->flags |= HLUA_MUST_GC;
+
if (!hlua_com_new(hlua, &appctx->ctx.hlua.wake_on_write))
WILL_LJMP(luaL_error(L, "out of memory"));
WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_socket_connect_yield, TICK_ETERNITY, 0));