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

new luv_cleanup to handle cleanup of non-gc resources #755

Closed
wants to merge 1 commit into from
Closed
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
7 changes: 6 additions & 1 deletion src/luv.c
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,11 @@ LUALIB_API void luv_set_loop(lua_State* L, uv_loop_t* loop) {
ctx->mode = -1;
}

// Clean up luv resources when using an external loop, after the loop has stopped.
LUALIB_API void luv_cleanup(void) {
luv_work_cleanup();
}

// Set an external event callback routine, before luaopen_luv
LUALIB_API void luv_set_callback(lua_State* L, luv_CFpcall pcall) {
luv_ctx_t* ctx = luv_context(L);
Expand Down Expand Up @@ -855,7 +860,7 @@ static int loop_gc(lua_State *L) {
/* do cleanup in main thread */
lua_getglobal(L, "_THREAD");
if (lua_isnil(L, -1))
luv_work_cleanup();
luv_cleanup();
lua_pop(L, 1);
return 0;
}
Expand Down
7 changes: 7 additions & 0 deletions src/luv.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ LUALIB_API uv_loop_t* luv_loop(lua_State* L);
*/
LUALIB_API void luv_set_loop(lua_State* L, uv_loop_t* loop);

/* Free all non-garbaged-collected resources allocated by luv. This function
must be called when using an external uv_loop_t, it is called during garbage
collection of the Lua userdata for the uv_loop_t otherwise. This must only
be called after all lua_States using luv have stopped their uv_loop_t.
*/
LUALIB_API void luv_cleanup(void);

/* Set or clear an external c routine for luv event callback
When using a custom/external function, this must be called before luaopen_luv
(otherwise luv will use the default callback function: luv_cfpcall)
Expand Down
Loading