mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 11:28:22 +00:00
fix(lua): only disable vim.schedule() when closing main loop (#26090)
This commit is contained in:
@@ -17,6 +17,7 @@ void loop_init(Loop *loop, void *data)
|
|||||||
{
|
{
|
||||||
uv_loop_init(&loop->uv);
|
uv_loop_init(&loop->uv);
|
||||||
loop->recursive = 0;
|
loop->recursive = 0;
|
||||||
|
loop->closing = false;
|
||||||
loop->uv.data = loop;
|
loop->uv.data = loop;
|
||||||
loop->children = kl_init(WatcherPtr);
|
loop->children = kl_init(WatcherPtr);
|
||||||
loop->events = multiqueue_new_parent(loop_on_put, loop);
|
loop->events = multiqueue_new_parent(loop_on_put, loop);
|
||||||
@@ -149,6 +150,7 @@ static void loop_walk_cb(uv_handle_t *handle, void *arg)
|
|||||||
bool loop_close(Loop *loop, bool wait)
|
bool loop_close(Loop *loop, bool wait)
|
||||||
{
|
{
|
||||||
bool rv = true;
|
bool rv = true;
|
||||||
|
loop->closing = true;
|
||||||
uv_mutex_destroy(&loop->mutex);
|
uv_mutex_destroy(&loop->mutex);
|
||||||
uv_close((uv_handle_t *)&loop->children_watcher, NULL);
|
uv_close((uv_handle_t *)&loop->children_watcher, NULL);
|
||||||
uv_close((uv_handle_t *)&loop->children_kill_timer, NULL);
|
uv_close((uv_handle_t *)&loop->children_kill_timer, NULL);
|
||||||
|
@@ -40,6 +40,7 @@ typedef struct loop {
|
|||||||
uv_async_t async;
|
uv_async_t async;
|
||||||
uv_mutex_t mutex;
|
uv_mutex_t mutex;
|
||||||
int recursive;
|
int recursive;
|
||||||
|
bool closing; ///< Set to true if loop_close() has been called
|
||||||
} Loop;
|
} Loop;
|
||||||
|
|
||||||
#define CREATE_EVENT(multiqueue, handler, argc, ...) \
|
#define CREATE_EVENT(multiqueue, handler, argc, ...) \
|
||||||
|
@@ -366,17 +366,17 @@ static void nlua_schedule_event(void **argv)
|
|||||||
static int nlua_schedule(lua_State *const lstate)
|
static int nlua_schedule(lua_State *const lstate)
|
||||||
FUNC_ATTR_NONNULL_ALL
|
FUNC_ATTR_NONNULL_ALL
|
||||||
{
|
{
|
||||||
// If Nvim is exiting don't schedule tasks to run in the future. Any refs
|
|
||||||
// allocated here will not be cleaned up otherwise
|
|
||||||
if (exiting) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lua_type(lstate, 1) != LUA_TFUNCTION) {
|
if (lua_type(lstate, 1) != LUA_TFUNCTION) {
|
||||||
lua_pushliteral(lstate, "vim.schedule: expected function");
|
lua_pushliteral(lstate, "vim.schedule: expected function");
|
||||||
return lua_error(lstate);
|
return lua_error(lstate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If main_loop is closing don't schedule tasks to run in the future,
|
||||||
|
// otherwise any refs allocated here will not be cleaned up.
|
||||||
|
if (main_loop.closing) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
LuaRef cb = nlua_ref_global(lstate, 1);
|
LuaRef cb = nlua_ref_global(lstate, 1);
|
||||||
|
|
||||||
multiqueue_put(main_loop.events, nlua_schedule_event,
|
multiqueue_put(main_loop.events, nlua_schedule_event,
|
||||||
|
Reference in New Issue
Block a user