]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: threads/lua: Ensure that the launched tasks runs on the same threads than me
authorThierry FOURNIER <thierry.fournier@ozon.io>
Wed, 12 Jul 2017 09:53:38 +0000 (11:53 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 31 Oct 2017 12:58:32 +0000 (13:58 +0100)
The applet manipulates the session and its buffers. We have two methods for
ensuring that the memory of the session will not change during its manipulation
by the task:
 1 - adding mutex
 2 - running on the same threads than the task.
The second point is smart because it cannot lock the execution of another thread.

src/hlua.c

index f966389a6562f7f52163bbcdf1668b72df025fc5..3bb46bb049e82114678a84f7ae50584f939bd1ba 100644 (file)
@@ -2407,7 +2407,7 @@ __LJMP static int hlua_socket_new(lua_State *L)
        lua_setmetatable(L, -2);
 
        /* Create the applet context */
-       appctx = appctx_new(&update_applet, MAX_THREADS_MASK);
+       appctx = appctx_new(&update_applet, 1UL << tid);
        if (!appctx) {
                hlua_pusherror(L, "socket: out of memory");
                goto out_fail_conf;
@@ -6062,7 +6062,7 @@ static int hlua_applet_tcp_init(struct appctx *ctx, struct proxy *px, struct str
        ctx->ctx.hlua_apptcp.flags = 0;
 
        /* Create task used by signal to wakeup applets. */
-       task = task_new(MAX_THREADS_MASK);
+       task = task_new(1UL << tid);
        if (!task) {
                SEND_ERR(px, "Lua applet tcp '%s': out of memory.\n",
                         ctx->rule->arg.hlua_rule->fcn.name);
@@ -6263,7 +6263,7 @@ static int hlua_applet_http_init(struct appctx *ctx, struct proxy *px, struct st
                ctx->ctx.hlua_apphttp.flags |= APPLET_HTTP11;
 
        /* Create task used by signal to wakeup applets. */
-       task = task_new(MAX_THREADS_MASK);
+       task = task_new(1UL << tid);
        if (!task) {
                SEND_ERR(px, "Lua applet http '%s': out of memory.\n",
                         ctx->rule->arg.hlua_rule->fcn.name);
@@ -6808,7 +6808,7 @@ static int hlua_cli_parse_fct(char **args, struct appctx *appctx, void *private)
         * We use the same wakeup fonction than the Lua applet_tcp and
         * applet_http. It is absolutely compatible.
         */
-       appctx->ctx.hlua_cli.task = task_new(MAX_THREADS_MASK);
+       appctx->ctx.hlua_cli.task = task_new(1UL << tid);
        if (!appctx->ctx.hlua_cli.task) {
                SEND_ERR(NULL, "Lua cli '%s': out of memory.\n", fcn->name);
                goto error;