]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: hlua: add core.wait()
authorAurelien DARRAGON <adarragon@haproxy.com>
Fri, 21 Mar 2025 08:37:38 +0000 (09:37 +0100)
committerAurelien DARRAGON <adarragon@haproxy.com>
Thu, 3 Apr 2025 15:52:23 +0000 (17:52 +0200)
Similar to core.yield(), except that the task is not woken up
automatically, instead it waits for events to trigger the task
wakeup.

Lua documentation was updated.

doc/lua-api/index.rst
src/hlua.c

index 456f915d4f60c02c057a013e48dc25852387de7b..267b9f42f859089d3f2a532093683b9868a6adea 100644 (file)
@@ -926,12 +926,21 @@ Core class
   its work and wants to give back the control to HAProxy without executing the
   remaining code. It can be seen as a multi-level "return".
 
+.. js:function:: core.wait()
+
+  **context**: task, action
+
+  Give back the hand at the HAProxy scheduler. Unlike :js:func:`core.yield`
+  the task will not be woken up automatically to resume as fast as possible.
+  Instead, it will wait for an event to wake the task.
+
 .. js:function:: core.yield()
 
   **context**: task, action
 
   Give back the hand at the HAProxy scheduler. It is used when the LUA
-  processing consumes a lot of processing time.
+  processing consumes a lot of processing time. Lua excecution will be resumed
+  automatically (automatic reschedule).
 
 .. js:function:: core.parse_addr(address)
 
index bc260f44e6b19c0a6cdd2fddb54654c8d2c3770f..ac253361b0c43e4b0f1db4bb102f03e01e28fdfe 100644 (file)
@@ -9247,6 +9247,17 @@ __LJMP static int hlua_yield(lua_State *L)
        return 0;
 }
 
+/* same as hlua_yield() but doesn't enforce CTRLYIELD so the Lua task won't be
+ * automatically woken up to resume ASAP, instead it means we will wait for
+ * an event to occur to wake the task. Only use when you're confident that
+ * something or someone will wake the task at some point.
+ */
+__LJMP static int hlua_wait(lua_State *L)
+{
+       MAY_LJMP(hlua_yieldk(L, 0, 0, hlua_yield_yield, TICK_ETERNITY, 0));
+       return 0;
+}
+
 /* This function change the nice of the currently executed
  * task. It is used set low or high priority at the current
  * task.
@@ -13877,6 +13888,7 @@ lua_State *hlua_init_state(int thread_num)
        hlua_class_function(L, "register_cli", hlua_register_cli);
        hlua_class_function(L, "register_filter", hlua_register_filter);
        hlua_class_function(L, "yield", hlua_yield);
+       hlua_class_function(L, "wait", hlua_wait);
        hlua_class_function(L, "set_nice", hlua_set_nice);
        hlua_class_function(L, "sleep", hlua_sleep);
        hlua_class_function(L, "msleep", hlua_msleep);