diff options
| author | Akshay Nair <phenax5@gmail.com> | 2025-03-23 18:27:52 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2025-03-23 18:34:50 +0530 |
| commit | 9cc72e8ea9f59f9a9627d05528d54a559ebd412c (patch) | |
| tree | 7007e42dbbd003f6c57d90d35b175983a2e829b7 /src/AsyncEventLoop.cpp | |
| parent | 18b3e4939931c0d2bf779d2e52cb0c90e282ec97 (diff) | |
| download | null-browser-9cc72e8ea9f59f9a9627d05528d54a559ebd412c.tar.gz null-browser-9cc72e8ea9f59f9a9627d05528d54a559ebd412c.zip | |
Fix segfault with luaruntime destructor
Diffstat (limited to '')
| -rw-r--r-- | src/AsyncEventLoop.cpp | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/src/AsyncEventLoop.cpp b/src/AsyncEventLoop.cpp index 6c6333f..230d891 100644 --- a/src/AsyncEventLoop.cpp +++ b/src/AsyncEventLoop.cpp @@ -3,6 +3,7 @@ #include <mutex> #include <queue> #include <thread> +#include <uv.h> #include "AsyncEventLoop.hpp" @@ -53,32 +54,36 @@ AsyncEventLoop::~AsyncEventLoop() { return; isLoopRunning = false; - // Wake it up. Stab it to death. (clear async queue) - wake(); - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - { - std::lock_guard<std::mutex> lock(tasksQueueMutex); - std::queue<std::function<void()>>().swap(tasksQueue); - } + flushTasks(); + std::this_thread::sleep_for(std::chrono::milliseconds(50)); uv_stop(loop); // Close all handles AsyncEventLoop::closeHandle(reinterpret_cast<uv_handle_t *>(&asyncHandle)); uv_walk(loop, AsyncEventLoop::closeHandle, nullptr); - 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) if (loopThread.joinable()) loopThread.join(); - while (uv_loop_close(loop)) - uv_run(loop, UV_RUN_DEFAULT); + // Close loop + while (uv_loop_close(loop) == EBUSY) + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + + uv_run(loop, UV_RUN_DEFAULT); + + if (uv_loop_alive(loop)) + qDebug() << "WARNING: Loop still has active handles!"; free(loop); loop = nullptr; } +void AsyncEventLoop::flushTasks() { + std::lock_guard<std::mutex> lock(tasksQueueMutex); + std::queue<std::function<void()>>().swap(tasksQueue); + wake(); +} + void AsyncEventLoop::asyncHandleCallback(uv_async_t *handle) { auto *runtime = static_cast<AsyncEventLoop *>(handle->data); runtime->processTasks(); |
