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.
This commit is contained in:
Christopher Faulet 2021-08-04 17:58:21 +02:00
parent 6fcd2d3280
commit 1f43a3430e
3 changed files with 8 additions and 0 deletions

View 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

View File

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

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