#define SET_SAFE_LJMP_L(__L, __HLUA) \
({ \
int ret; \
- if ((__HLUA)->state_from == gL.T) \
+ if ((__HLUA)->state_from == hlua_states[0]) \
HA_SPIN_LOCK(LUA_LOCK, &hlua_global_lock); \
if (setjmp(safe_ljmp_env) != 0) { \
lua_atpanic(__L, hlua_panic_safe); \
ret = 0; \
- if ((__HLUA)->state_from == gL.T) \
+ if ((__HLUA)->state_from == hlua_states[0]) \
HA_SPIN_UNLOCK(LUA_LOCK, &hlua_global_lock); \
} else { \
lua_atpanic(__L, hlua_panic_ljmp); \
#define RESET_SAFE_LJMP_L(__L, __HLUA) \
do { \
lua_atpanic(__L, hlua_panic_safe); \
- if ((__HLUA)->state_from == gL.T) \
+ if ((__HLUA)->state_from == hlua_states[0]) \
HA_SPIN_UNLOCK(LUA_LOCK, &hlua_global_lock); \
} while(0)
#define APPLET_HTTP11 0x20 /* Last chunk sent. */
#define APPLET_RSP_SENT 0x40 /* The response was fully sent */
-/* The main Lua execution context. */
-struct {
- lua_State *T;
-} gL;
+/* The main Lua execution context. The 0 index is the
+ * common state shared by all threads.
+ */
+lua_State *hlua_states[MAX_THREADS + 1];
/* This is the memory pool containing struct lua for applets
* (including cli).
/* Lock the whole Lua execution. This lock must be before the
* label "resume_execution".
*/
- if (lua->state_from == gL.T)
+ if (lua->state_from == hlua_states[0])
HA_SPIN_LOCK(LUA_LOCK, &hlua_global_lock);
resume_execution:
}
/* This is the main exit point, remove the Lua lock. */
- if (lua->state_from == gL.T)
+ if (lua->state_from == hlua_states[0])
HA_SPIN_UNLOCK(LUA_LOCK, &hlua_global_lock);
return ret;
SEND_ERR(stream->be, "Lua converter '%s': can't initialize Lua context.\n", fcn->name);
return 0;
}
- if (!hlua_ctx_init(stream->hlua, gL.T, stream->task, 0)) {
+ if (!hlua_ctx_init(stream->hlua, hlua_states[0], stream->task, 0)) {
SEND_ERR(stream->be, "Lua converter '%s': can't initialize Lua context.\n", fcn->name);
return 0;
}
SEND_ERR(stream->be, "Lua sample-fetch '%s': can't initialize Lua context.\n", fcn->name);
return 0;
}
- if (!hlua_ctx_init(stream->hlua, gL.T, stream->task, 0)) {
+ if (!hlua_ctx_init(stream->hlua, hlua_states[0], stream->task, 0)) {
SEND_ERR(stream->be, "Lua sample-fetch '%s': can't initialize Lua context.\n", fcn->name);
return 0;
}
rule->arg.hlua_rule->fcn->name);
goto end;
}
- if (!hlua_ctx_init(s->hlua, gL.T, s->task, 0)) {
+ if (!hlua_ctx_init(s->hlua, hlua_states[0], s->task, 0)) {
SEND_ERR(px, "Lua action '%s': can't initialize Lua context.\n",
rule->arg.hlua_rule->fcn->name);
goto end;
* permits to save performances because a systematic
* Lua initialization cause 5% performances loss.
*/
- if (!hlua_ctx_init(hlua, gL.T, task, 0)) {
+ if (!hlua_ctx_init(hlua, hlua_states[0], task, 0)) {
SEND_ERR(px, "Lua applet tcp '%s': can't initialize Lua context.\n",
ctx->rule->arg.hlua_rule->fcn->name);
return 0;
* permits to save performances because a systematic
* Lua initialization cause 5% performances loss.
*/
- if (!hlua_ctx_init(hlua, gL.T, task, 0)) {
+ if (!hlua_ctx_init(hlua, hlua_states[0], task, 0)) {
SEND_ERR(px, "Lua applet http '%s': can't initialize Lua context.\n",
ctx->rule->arg.hlua_rule->fcn->name);
return 0;
appctx->ctx.hlua_cli.task->process = hlua_applet_wakeup;
/* Initialises the Lua context */
- if (!hlua_ctx_init(hlua, gL.T, appctx->ctx.hlua_cli.task, 0)) {
+ if (!hlua_ctx_init(hlua, hlua_states[0], appctx->ctx.hlua_cli.task, 0)) {
SEND_ERR(NULL, "Lua cli '%s': can't initialize Lua context.\n", fcn->name);
goto error;
}
return -1;
}
- return hlua_load_state(args[1], gL.T, err);
+ return hlua_load_state(args[1], hlua_states[0], err);
}
/* Prepend the given <path> followed by a semicolon to the `package.<type>` variable
type = args[2];
}
- return hlua_prepend_path(gL.T, type, path);
+ return hlua_prepend_path(hlua_states[0], type, path);
}
/* configuration keywords declaration */
}
#endif
- return hlua_post_init_state(gL.T);
+ return hlua_post_init_state(hlua_states[0]);
}
/* The memory allocator used by the Lua stack. <ud> is a pointer to the
}
void hlua_init(void) {
- gL.T = hlua_init_state(0);
+ hlua_states[0] = hlua_init_state(0);
}
static void hlua_deinit()
{
- lua_close(gL.T);
+ lua_close(hlua_states[0]);
}
REGISTER_POST_DEINIT(hlua_deinit);