From efca07cae13ee798509050f8ecc55d3c5e2b187d Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Wed, 4 Aug 2021 17:58:21 +0200 Subject: [PATCH] MINOR: lua: Add a flag on lua context to know the yield capability at run time When a script is executed, a flag is used to allow it to yield. An error is returned if a lua function yield, explicitly or not. But there is no way to get this capability in C functions. So there is no way to choose to yield or not depending on this capability. To fill this gap, the flag HLUA_NOYIELD is introduced and added on the lua context if the current script execution is not authorized to yield. Macros to set, clear and test this flags are also added. This feature will be usefull to fix some bugs in lua actions execution. (cherry picked from commit a6e792ff52f895234bb1499e9df5417bf498a8f8) Signed-off-by: Christopher Faulet --- include/haproxy/hlua-t.h | 1 + include/haproxy/hlua.h | 4 ++++ src/hlua.c | 3 +++ 3 files changed, 8 insertions(+) diff --git a/include/haproxy/hlua-t.h b/include/haproxy/hlua-t.h index 391310c..0bc79de 100644 --- a/include/haproxy/hlua-t.h +++ b/include/haproxy/hlua-t.h @@ -58,6 +58,7 @@ struct stream; #define HLUA_WAKERESWR 0x00000004 #define HLUA_WAKEREQWR 0x00000008 #define HLUA_EXIT 0x00000010 +#define HLUA_NOYIELD 0x00000020 #define HLUA_F_AS_STRING 0x01 #define HLUA_F_MAY_USE_HTTP 0x02 diff --git a/include/haproxy/hlua.h b/include/haproxy/hlua.h index b4e56d4..8b26b9c 100644 --- a/include/haproxy/hlua.h +++ b/include/haproxy/hlua.h @@ -39,6 +39,10 @@ #define HLUA_SET_WAKEREQWR(__hlua) do {(__hlua)->flags |= HLUA_WAKEREQWR;} while(0) #define HLUA_CLR_WAKEREQWR(__hlua) do {(__hlua)->flags &= ~HLUA_WAKEREQWR;} while(0) #define HLUA_IS_WAKEREQWR(__hlua) ((__hlua)->flags & HLUA_WAKEREQWR) +#define HLUA_CLR_NOYIELD(__hlua) do {(__hlua)->flags &= ~HLUA_NOYIELD;} while(0) +#define HLUA_SET_NOYIELD(__hlua) do {(__hlua)->flags |= HLUA_NOYIELD;} while(0) +#define HLUA_CANT_YIELD(__hlua) ((__hlua)->flags & HLUA_NOYIELD) + #define HLUA_INIT(__hlua) do { (__hlua)->T = 0; } while(0) diff --git a/src/hlua.c b/src/hlua.c index 9287952..7335fb4 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -1202,6 +1202,9 @@ resume_execution: HLUA_CLR_CTRLYIELD(lua); HLUA_CLR_WAKERESWR(lua); HLUA_CLR_WAKEREQWR(lua); + HLUA_CLR_NOYIELD(lua); + if (!yield_allowed) + HLUA_SET_NOYIELD(lua); /* Update the start time and reset wake_time. */ lua->start_time = now_ms; -- 1.7.10.4