mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-22 22:31:28 +02:00
MEDIUM: lua: make the functions hlua_gethlua() and hlua_sethlua() faster
Lua 5.3 provides an opaque space associated with each coroutine stack. This patch uses this lot of memory to store the "struct hlua *" associated pointer. This patch makes the retrieval of the "struct hlua *" associated struct faster because it replace a lookup in a tree by an immediate access to the data.
This commit is contained in:
parent
76bd97f405
commit
38c5fd60b9
32
src/hlua.c
32
src/hlua.c
@ -64,12 +64,6 @@ static struct server socket_ssl;
|
|||||||
/* List head of the function called at the initialisation time. */
|
/* List head of the function called at the initialisation time. */
|
||||||
struct list hlua_init_functions = LIST_HEAD_INIT(hlua_init_functions);
|
struct list hlua_init_functions = LIST_HEAD_INIT(hlua_init_functions);
|
||||||
|
|
||||||
/* Store the fast lua context for coroutines. This tree uses the
|
|
||||||
* Lua stack pointer value as indexed entry, and store the associated
|
|
||||||
* hlua context.
|
|
||||||
*/
|
|
||||||
struct eb_root hlua_ctx = EB_ROOT_UNIQUE;
|
|
||||||
|
|
||||||
/* The following variables contains the reference of the different
|
/* The following variables contains the reference of the different
|
||||||
* Lua classes. These references are useful for identify metadata
|
* Lua classes. These references are useful for identify metadata
|
||||||
* associated with an object.
|
* associated with an object.
|
||||||
@ -506,31 +500,19 @@ __LJMP int hlua_lua2arg_check(lua_State *L, int first, struct arg *argp, unsigne
|
|||||||
/*
|
/*
|
||||||
* The following functions are used to make correspondance between the the
|
* The following functions are used to make correspondance between the the
|
||||||
* executed lua pointer and the "struct hlua *" that contain the context.
|
* executed lua pointer and the "struct hlua *" that contain the context.
|
||||||
* They run with the tree head "hlua_ctx", they just perform lookup in the
|
|
||||||
* tree.
|
|
||||||
*
|
*
|
||||||
* - hlua_gethlua : return the hlua context associated with an lua_State.
|
* - hlua_gethlua : return the hlua context associated with an lua_State.
|
||||||
* - hlua_delhlua : remove the association between hlua context and lua_state.
|
|
||||||
* - hlua_sethlua : create the association between hlua context and lua_state.
|
* - hlua_sethlua : create the association between hlua context and lua_state.
|
||||||
*/
|
*/
|
||||||
static inline struct hlua *hlua_gethlua(lua_State *L)
|
static inline struct hlua *hlua_gethlua(lua_State *L)
|
||||||
{
|
{
|
||||||
struct ebpt_node *node;
|
struct hlua **hlua = lua_getextraspace(L);
|
||||||
|
return *hlua;
|
||||||
node = ebpt_lookup(&hlua_ctx, L);
|
|
||||||
if (!node)
|
|
||||||
return NULL;
|
|
||||||
return ebpt_entry(node, struct hlua, node);
|
|
||||||
}
|
|
||||||
static inline void hlua_delhlua(struct hlua *hlua)
|
|
||||||
{
|
|
||||||
if (hlua->node.key)
|
|
||||||
ebpt_delete(&hlua->node);
|
|
||||||
}
|
}
|
||||||
static inline void hlua_sethlua(struct hlua *hlua)
|
static inline void hlua_sethlua(struct hlua *hlua)
|
||||||
{
|
{
|
||||||
hlua->node.key = hlua->T;
|
struct hlua **hlua_store = lua_getextraspace(hlua->T);
|
||||||
ebpt_insert(&hlua_ctx, &hlua->node);
|
*hlua_store = hlua;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This function just ensure that the yield will be always
|
/* This function just ensure that the yield will be always
|
||||||
@ -581,9 +563,6 @@ void hlua_ctx_destroy(struct hlua *lua)
|
|||||||
if (!lua->T)
|
if (!lua->T)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* Remove context. */
|
|
||||||
hlua_delhlua(lua);
|
|
||||||
|
|
||||||
/* Purge all the pending signals. */
|
/* Purge all the pending signals. */
|
||||||
hlua_com_purge(lua);
|
hlua_com_purge(lua);
|
||||||
|
|
||||||
@ -608,9 +587,6 @@ static int hlua_ctx_renew(struct hlua *lua, int keep_msg)
|
|||||||
if (lua == &gL)
|
if (lua == &gL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* Remove context. */
|
|
||||||
hlua_delhlua(lua);
|
|
||||||
|
|
||||||
/* New Lua coroutine. */
|
/* New Lua coroutine. */
|
||||||
T = lua_newthread(gL.T);
|
T = lua_newthread(gL.T);
|
||||||
if (!T)
|
if (!T)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user