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

move luv_work_cleanup into loop gc #742

Merged
merged 2 commits into from
Dec 21, 2024
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
11 changes: 5 additions & 6 deletions src/luv.c
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,11 @@ static int loop_gc(lua_State *L) {
while (uv_loop_close(loop)) {
uv_run(loop, UV_RUN_DEFAULT);
}
/* do cleanup in main thread */
lua_getglobal(L, "_THREAD");
if (lua_isnil(L, -1))
luv_work_cleanup();
lua_pop(L, 1);
return 0;
}

Expand Down Expand Up @@ -885,12 +890,6 @@ LUALIB_API int luaopen_luv (lua_State* L) {
if (ret < 0) {
return luaL_error(L, "%s: %s\n", uv_err_name(ret), uv_strerror(ret));
}

/* do cleanup in main thread */
lua_getglobal(L, "_THREAD");
if (lua_isnil(L, -1))
atexit(luv_work_cleanup);
lua_pop(L, 1);
}
// pcall is NULL, luv use default callback routine
if (ctx->cb_pcall==NULL) {
Expand Down
2 changes: 1 addition & 1 deletion src/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ static lua_State *vm_acquire(uv_loop_t* loop) {
static void vm_release(lua_State* L) { lua_close(L); }


static lua_State* luv_thread_acquire_vm() {
static lua_State* luv_thread_acquire_vm(void) {
lua_State* L = vm_acquire(NULL); /* create state */

lua_pushboolean(L, 1);
Expand Down
Loading