From 4325ab727ca4ba07a68d37bd35c464d46b7f8cdb Mon Sep 17 00:00:00 2001 From: Thierry FOURNIER Date: Wed, 12 Jul 2017 11:53:38 +0200 Subject: [PATCH] MEDIUM: threads/lua: Ensure that the launched tasks runs on the same threads than me 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 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/hlua.c b/src/hlua.c index f966389a65..3bb46bb049 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -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; -- 2.47.3