MCPcopy Create free account
hub / github.com/apache/trafficserver / ts_lua_create_async_ctx

Function ts_lua_create_async_ctx

plugins/lua/ts_lua_util.cc:614–653  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

612}
613
614ts_lua_http_ctx *
615ts_lua_create_async_ctx(lua_State *L, ts_lua_cont_info *hci, int n)
616{
617 int i;
618 lua_State *l;
619 ts_lua_coroutine *crt;
620 ts_lua_http_ctx *actx;
621
622 actx = TSRalloc<ts_lua_http_ctx>();
623 memset(actx, 0, sizeof(*actx));
624
625 // create lua_thread
626 l = lua_newthread(L);
627
628 // init the coroutine
629 crt = &actx->cinfo.routine;
630 crt->mctx = hci->routine.mctx;
631 crt->lua = l;
632 crt->ref = luaL_ref(L, LUA_REGISTRYINDEX);
633
634 // update thread stats
635 ts_lua_main_ctx *const main_ctx = crt->mctx;
636 ts_lua_ctx_stats *const stats = main_ctx->stats;
637
638 TSMutexLock(stats->mutexp);
639 ++stats->threads;
640 if (stats->threads_max < stats->threads) {
641 stats->threads_max = stats->threads;
642 }
643 TSMutexUnlock(stats->mutexp);
644
645 // replace the param; start with 2 because first two params are not needed
646 for (i = 2; i < n; i++) {
647 lua_pushvalue(L, i + 1);
648 }
649
650 lua_xmove(L, l, n - 2);
651
652 return actx;
653}
654
655void
656ts_lua_destroy_async_ctx(ts_lua_http_ctx *http_ctx)

Callers 1

ts_lua_scheduleFunction · 0.85

Calls 3

memsetFunction · 0.85
TSMutexLockFunction · 0.85
TSMutexUnlockFunction · 0.85

Tested by

no test coverage detected