Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize: now we make use of the new lua_getexdata2 and lua_setexdata… #319

Merged
merged 1 commit into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/ngx_stream_lua_contentby.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ ngx_stream_lua_content_by_chunk(lua_State *L, ngx_stream_lua_request_t *r)
ctx->cur_co_ctx->co_top = 1;
#endif

ngx_stream_lua_attach_co_ctx_to_L(co, ctx->cur_co_ctx);

/* {{{ register request cleanup hooks */
if (ctx->cleanup == NULL) {
cln = ngx_stream_lua_cleanup_add(r, 0);
Expand Down
1 change: 1 addition & 0 deletions src/ngx_stream_lua_coroutine.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ ngx_stream_lua_coroutine_create_helper(lua_State *L,

#ifdef OPENRESTY_LUAJIT
ngx_stream_lua_set_req(co, r);
ngx_stream_lua_attach_co_ctx_to_L(co, coctx);
#else
/* make new coroutine share globals of the parent coroutine.
* NOTE: globals don't have to be separated! */
Expand Down
9 changes: 9 additions & 0 deletions src/ngx_stream_lua_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,15 @@ ngx_stream_lua_init(ngx_conf_t *cf)
"the OpenResty releases from https://openresty.org/"
"en/download.html)");
}
#else
# if !defined(HAVE_LUA_EXDATA2)
ngx_log_error(NGX_LOG_ALERT, cf->log, 0,
"detected an old version of OpenResty's LuaJIT missing "
"the exdata2 API and thus the "
"performance will be compromised; please upgrade to the "
"latest version of OpenResty's LuaJIT: "
"https://github.com/openresty/luajit2");
# endif
#endif


Expand Down
2 changes: 2 additions & 0 deletions src/ngx_stream_lua_prereadby.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ ngx_stream_lua_preread_by_chunk(lua_State *L, ngx_stream_lua_request_t *r)
ctx->cur_co_ctx->co_top = 1;
#endif

ngx_stream_lua_attach_co_ctx_to_L(co, ctx->cur_co_ctx);

/* }}} */

/* {{{ register request cleanup hooks */
Expand Down
2 changes: 2 additions & 0 deletions src/ngx_stream_lua_ssl_certby.c
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,8 @@ ngx_stream_lua_ssl_cert_by_chunk(lua_State *L, ngx_stream_lua_request_t *r)
ctx->cur_co_ctx->co_top = 1;
#endif

ngx_stream_lua_attach_co_ctx_to_L(co, ctx->cur_co_ctx);

/* register request cleanup hooks */
if (ctx->cleanup == NULL) {
cln = ngx_stream_lua_cleanup_add(r, 0);
Expand Down
2 changes: 2 additions & 0 deletions src/ngx_stream_lua_ssl_client_helloby.c
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,8 @@ ngx_stream_lua_ssl_client_hello_by_chunk(lua_State *L,
ctx->cur_co_ctx->co_top = 1;
#endif

ngx_stream_lua_attach_co_ctx_to_L(co, ctx->cur_co_ctx);

/* register request cleanup hooks */
if (ctx->cleanup == NULL) {
cln = ngx_stream_lua_cleanup_add(r, 0);
Expand Down
2 changes: 2 additions & 0 deletions src/ngx_stream_lua_timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,8 @@ ngx_stream_lua_timer_handler(ngx_event_t *ev)
/* save the request in coroutine globals table */
ngx_stream_lua_set_req(tctx.co, r);

ngx_stream_lua_attach_co_ctx_to_L(tctx.co, ctx->cur_co_ctx);

lmcf->running_timers++;

lua_pushboolean(tctx.co, tctx.premature);
Expand Down
2 changes: 2 additions & 0 deletions src/ngx_stream_lua_uthread.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ ngx_stream_lua_uthread_spawn(lua_State *L)
coctx->parent_co_ctx = ctx->cur_co_ctx;
ctx->cur_co_ctx = coctx;

ngx_stream_lua_attach_co_ctx_to_L(coctx->co, coctx);

ngx_stream_lua_probe_user_thread_spawn(r, L, coctx->co);

dd("yielding with arg %s, top=%d, index-1:%s", luaL_typename(L, -1),
Expand Down
4 changes: 4 additions & 0 deletions src/ngx_stream_lua_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -2590,6 +2590,9 @@ ngx_stream_lua_traceback(lua_State *L)
ngx_stream_lua_co_ctx_t *
ngx_stream_lua_get_co_ctx(lua_State *L, ngx_stream_lua_ctx_t *ctx)
{
#ifdef HAVE_LUA_EXDATA2
return (ngx_stream_lua_co_ctx_t *) lua_getexdata2(L);
#else
ngx_uint_t i;
ngx_list_part_t *part;

Expand Down Expand Up @@ -2626,6 +2629,7 @@ ngx_stream_lua_get_co_ctx(lua_State *L, ngx_stream_lua_ctx_t *ctx)
}

return NULL;
#endif
}


Expand Down
10 changes: 10 additions & 0 deletions src/ngx_stream_lua_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,16 @@ ngx_int_t ngx_stream_lua_open_and_stat_file(u_char *name,
ngx_chain_t *ngx_stream_lua_chain_get_free_buf(ngx_log_t *log, ngx_pool_t *p,
ngx_chain_t **free, size_t len);


static ngx_inline void
ngx_stream_lua_attach_co_ctx_to_L(lua_State *L, ngx_stream_lua_co_ctx_t *coctx)
{
#ifdef HAVE_LUA_EXDATA2
lua_setexdata2(L, (void *) coctx);
#endif
}


#ifndef OPENRESTY_LUAJIT
void ngx_stream_lua_create_new_globals_table(lua_State *L, int narr, int nrec);
#endif
Expand Down
Loading