aboutsummaryrefslogtreecommitdiff
path: root/src/AsyncEventLoop.cpp
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2025-03-23 16:59:16 +0530
committerAkshay Nair <phenax5@gmail.com>2025-03-23 16:59:34 +0530
commit18b3e4939931c0d2bf779d2e52cb0c90e282ec97 (patch)
treee9afabef77660b8cfcd8a37006c9db38c4bc8aa6 /src/AsyncEventLoop.cpp
parent1f018902a8e1d1138c9a56106bce7aa7982a247b (diff)
downloadnull-browser-18b3e4939931c0d2bf779d2e52cb0c90e282ec97.tar.gz
null-browser-18b3e4939931c0d2bf779d2e52cb0c90e282ec97.zip
Fix segfault with evaluate, add keymap accidentally popping wrong value
+ add demnu config.lua example
Diffstat (limited to 'src/AsyncEventLoop.cpp')
-rw-r--r--src/AsyncEventLoop.cpp33
1 files changed, 14 insertions, 19 deletions
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 <mutex>
#include <queue>
#include <thread>
-#include <utility>
-#include <uv.h>
#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<std::function<void()>> 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<std::mutex> lock(tasksQueueMutex);
std::queue<std::function<void()>>().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<uv_handle_t *>(&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);
}
}