]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: lua: Add a flag on lua context to know the yield capability at run time
authorChristopher Faulet <cfaulet@haproxy.com>
Wed, 4 Aug 2021 15:58:21 +0000 (17:58 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Thu, 12 Aug 2021 06:57:07 +0000 (08:57 +0200)
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.

include/haproxy/hlua-t.h
include/haproxy/hlua.h
src/hlua.c

index 964654c44a3255cd0db55b10afc73893a720ba01..775c8535e4472675376221c6312de7268dfc3036 100644 (file)
@@ -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
index f139552968a6d2a72aed98d614ff4fa491bf5d60..21e4534affce8116da868c0e46e888b349da4640 100644 (file)
 #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)
 
index 6a9073e311b4b609ff8b7377faefc9842c593d8e..0de63422dc92e1789c5793f9bdb8df39edb8044b 100644 (file)
@@ -1277,6 +1277,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;