From 2a9764baae98a5f95ef08ea57129880ef223c268 Mon Sep 17 00:00:00 2001 From: Aurelien DARRAGON Date: Tue, 4 Apr 2023 18:41:04 +0200 Subject: [PATCH] CLEANUP: hlua: avoid confusion between internal timers and tick based timers Not all hlua "time" variables use the same time logic. hlua->wake_time relies on ticks since its meant to be used in conjunction with task scheduling. Thus, it should be stored as a signed int and manipulated using the tick api. Adding a few comments about that to prevent mixups with hlua internal timer api which doesn't rely on the ticks api. --- include/haproxy/hlua-t.h | 2 +- src/hlua.c | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/include/haproxy/hlua-t.h b/include/haproxy/hlua-t.h index 22de65932d..2672ffdcf4 100644 --- a/include/haproxy/hlua-t.h +++ b/include/haproxy/hlua-t.h @@ -116,7 +116,7 @@ struct hlua { -1 if the memory context is not used. */ int nargs; /* The number of arguments in the stack at the start of execution. */ unsigned int flags; /* The current execution flags. */ - int wake_time; /* The lua wants to be waked at this time, or before. */ + int wake_time; /* The lua wants to be waked at this time, or before. (ticks) */ struct hlua_timer timer; /* lua multipurpose timer */ struct task *task; /* The task associated with the lua stack execution. We must wake this task to continue the task execution */ diff --git a/src/hlua.c b/src/hlua.c index bea0cf754a..356c04c1b4 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -1369,6 +1369,7 @@ static inline void hlua_sendlog(struct proxy *px, int level, const char *msg) /* This function just ensure that the yield will be always * returned with a timeout and permit to set some flags + * is a tick value */ __LJMP void hlua_yieldk(lua_State *L, int nresults, int ctx, lua_KFunction k, int timeout, unsigned int flags) @@ -8627,7 +8628,7 @@ __LJMP static int hlua_sleep_yield(lua_State *L, int status, lua_KContext ctx) __LJMP static int hlua_sleep(lua_State *L) { unsigned int delay; - unsigned int wakeup_ms; + int wakeup_ms; // tick value MAY_LJMP(check_args(L, 1, "sleep")); @@ -8642,7 +8643,7 @@ __LJMP static int hlua_sleep(lua_State *L) __LJMP static int hlua_msleep(lua_State *L) { unsigned int delay; - unsigned int wakeup_ms; + int wakeup_ms; // tick value MAY_LJMP(check_args(L, 1, "msleep")); @@ -9814,7 +9815,7 @@ __LJMP static int hlua_set_wake_time(lua_State *L) { struct hlua *hlua; unsigned int delay; - unsigned int wakeup_ms; + int wakeup_ms; // tick value /* Get hlua struct, or NULL if we execute from main lua state */ hlua = hlua_gethlua(L); -- 2.47.3