]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: hlua: add hlua_nb_instruction getter
authorAurelien DARRAGON <adarragon@haproxy.com>
Wed, 15 May 2024 08:19:46 +0000 (10:19 +0200)
committerAurelien DARRAGON <adarragon@haproxy.com>
Wed, 15 May 2024 09:59:37 +0000 (11:59 +0200)
No functional behavior change, but this will ease the work of dynamically
computing hlua_nb_instruction value depending on various inputs.

src/hlua.c

index 0ef050c894f0721cffc4dc2aeacbba82f40a046a..6fe64be85abae7e492170e3afb8b99253d629f27 100644 (file)
@@ -541,6 +541,14 @@ static inline int hlua_timer_check(const struct hlua_timer *timer)
  */
 static unsigned int hlua_nb_instruction = 10000;
 
+/* Wrapper to retrieve the number of instructions between two interrupts
+ * depending on user settings and current hlua context.
+ */
+static inline unsigned int hlua_get_nb_instruction(struct hlua *hlua)
+{
+       return hlua_nb_instruction;
+}
+
 /* Descriptor for the memory allocation state. The limit is pre-initialised to
  * 0 until it is replaced by "tune.lua.maxmem" during the config parsing, or it
  * is replaced with ~0 during post_init after everything was loaded. This way
@@ -1783,7 +1791,7 @@ void hlua_hook(lua_State *L, lua_Debug *ar)
        /* Try to interrupt the process at the end of the current
         * unyieldable function.
         */
-       lua_sethook(hlua->T, hlua_hook, LUA_MASKRET|LUA_MASKCOUNT, hlua_nb_instruction);
+       lua_sethook(hlua->T, hlua_hook, LUA_MASKRET|LUA_MASKCOUNT, hlua_get_nb_instruction(hlua));
 }
 
 /* This function start or resumes the Lua stack execution. If the flag
@@ -1823,10 +1831,10 @@ static enum hlua_exec hlua_ctx_resume(struct hlua *lua, int yield_allowed)
 
 resume_execution:
 
-       /* This hook interrupts the Lua processing each 'hlua_nb_instruction'
+       /* This hook interrupts the Lua processing each 'hlua_get_nb_instruction()
         * instructions. it is used for preventing infinite loops.
         */
-       lua_sethook(lua->T, hlua_hook, LUA_MASKCOUNT, hlua_nb_instruction);
+       lua_sethook(lua->T, hlua_hook, LUA_MASKCOUNT, hlua_get_nb_instruction(lua));
 
        /* Remove all flags except the running flags. */
        HLUA_SET_RUN(lua);