From 18b3e4939931c0d2bf779d2e52cb0c90e282ec97 Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Sun, 23 Mar 2025 16:59:16 +0530 Subject: Fix segfault with evaluate, add keymap accidentally popping wrong value + add demnu config.lua example --- src/AsyncEventLoop.cpp | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) (limited to 'src/AsyncEventLoop.cpp') diff --git a/src/AsyncEventLoop.cpp b/src/AsyncEventLoop.cpp index 6c9b42d..6c6333f 100644 --- a/src/AsyncEventLoop.cpp +++ b/src/AsyncEventLoop.cpp @@ -3,8 +3,6 @@ #include #include #include -#include -#include #include "AsyncEventLoop.hpp" @@ -23,6 +21,8 @@ AsyncEventLoop::AsyncEventLoop() { std::this_thread::sleep_for(std::chrono::milliseconds(50)); } +void AsyncEventLoop::wake() { uv_async_send(&asyncHandle); } + void AsyncEventLoop::processTasks() { std::queue> tasks; @@ -41,10 +41,9 @@ void AsyncEventLoop::processTasks() { void AsyncEventLoop::runLoop() { isLoopRunning = true; while (isLoopRunning) { - /* int _result = */ uv_run(loop, UV_RUN_NOWAIT); - // qDebug() << "Tasks handled:" << result; - // uv_print_active_handles(loop, stdout); - // if (result == 0) + // qDebug() << "loop iteration" << uv_loop_alive(loop); + uv_run(loop, UV_RUN_NOWAIT); + // qDebug() << "uv_run() returned: " << result; std::this_thread::sleep_for(std::chrono::milliseconds(10)); } } @@ -54,33 +53,28 @@ AsyncEventLoop::~AsyncEventLoop() { return; isLoopRunning = false; - // Clear the tasks queue + // Wake it up. Stab it to death. (clear async queue) + wake(); + std::this_thread::sleep_for(std::chrono::milliseconds(100)); { std::lock_guard lock(tasksQueueMutex); std::queue>().swap(tasksQueue); } - - // Wake it up. Stab it to death. - uv_async_send(&asyncHandle); - std::this_thread::sleep_for(std::chrono::milliseconds(100)); uv_stop(loop); // Close all handles AsyncEventLoop::closeHandle(reinterpret_cast(&asyncHandle)); uv_walk(loop, AsyncEventLoop::closeHandle, nullptr); - while (uv_run(loop, UV_RUN_ONCE) != 0) - ; + while (uv_run(loop, UV_RUN_NOWAIT) != 0) + std::this_thread::sleep_for(std::chrono::milliseconds(100)); // TODO: Fix pending handler case (setTimeout(100) wait(20) close() -> error) - qDebug() << "join start"; if (loopThread.joinable()) loopThread.join(); - qDebug() << "join done"; - while (uv_loop_close(loop) == UV_EBUSY) { - uv_walk(loop, AsyncEventLoop::closeHandle, nullptr); - uv_run(loop, UV_RUN_NOWAIT); - } + while (uv_loop_close(loop)) + uv_run(loop, UV_RUN_DEFAULT); + free(loop); loop = nullptr; } @@ -93,5 +87,6 @@ void AsyncEventLoop::asyncHandleCallback(uv_async_t *handle) { void AsyncEventLoop::closeHandle(uv_handle_t *handle, void *) { if (!uv_is_closing(handle)) { uv_close(handle, [](uv_handle_t *h) { h->data = nullptr; }); + uv_unref(handle); } } -- cgit v1.3.1