| 349 | } |
| 350 | |
| 351 | static int |
| 352 | ts_lua_schedule_handler(TSCont contp, TSEvent ev, void *edata) |
| 353 | { |
| 354 | lua_State *L; |
| 355 | ts_lua_cont_info *ci; |
| 356 | ts_lua_coroutine *crt; |
| 357 | int event, n, ret; |
| 358 | ts_lua_http_ctx *actx; |
| 359 | ts_lua_main_ctx *main_ctx; |
| 360 | |
| 361 | event = (int)ev; |
| 362 | Dbg(dbg_ctl, "getting actx and other info"); |
| 363 | actx = (ts_lua_http_ctx *)TSContDataGet(contp); |
| 364 | |
| 365 | Dbg(dbg_ctl, "getting http_Ctx"); |
| 366 | ci = &actx->cinfo; |
| 367 | crt = &ci->routine; |
| 368 | |
| 369 | main_ctx = crt->mctx; |
| 370 | L = crt->lua; |
| 371 | |
| 372 | TSMutexLock(main_ctx->mutexp); |
| 373 | ts_lua_set_cont_info(L, ci); |
| 374 | |
| 375 | if (event == TS_LUA_EVENT_COROUTINE_CONT) { |
| 376 | Dbg(dbg_ctl, "event is coroutine_cont"); |
| 377 | n = (intptr_t)edata; |
| 378 | ret = lua_resume(L, n); |
| 379 | } else { |
| 380 | Dbg(dbg_ctl, "event is not coroutine_cont"); |
| 381 | n = lua_gettop(L); |
| 382 | ret = lua_resume(L, n - 1); |
| 383 | } |
| 384 | |
| 385 | if (ret == LUA_YIELD) { |
| 386 | TSMutexUnlock(main_ctx->mutexp); |
| 387 | goto done; |
| 388 | } |
| 389 | |
| 390 | if (ret != 0) { |
| 391 | TSError("[ts_lua][%s] lua_resume failed: %s", __FUNCTION__, lua_tostring(L, -1)); |
| 392 | } |
| 393 | |
| 394 | lua_pop(L, lua_gettop(L)); |
| 395 | TSMutexUnlock(main_ctx->mutexp); |
| 396 | ts_lua_destroy_async_ctx(actx); |
| 397 | |
| 398 | done: |
| 399 | return 0; |
| 400 | } |
| 401 | |
| 402 | static int |
| 403 | ts_lua_sleep_ms(lua_State *L) |
nothing calls this directly
no test coverage detected