From 0b5085db82c06b4dfd9d46dafeee8e3a3e4b21ce Mon Sep 17 00:00:00 2001 From: Yuqian Yang Date: Sun, 7 Sep 2025 21:57:02 +0800 Subject: Base test for event loop. --- src/base/platform/unix/EventLoop.cpp | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/base/platform/unix/EventLoop.cpp b/src/base/platform/unix/EventLoop.cpp index 8fe3b7ad..c6a80835 100644 --- a/src/base/platform/unix/EventLoop.cpp +++ b/src/base/platform/unix/EventLoop.cpp @@ -1,6 +1,5 @@ #include "cru/base/platform/unix/EventLoop.h" #include "cru/base/Exception.h" -#include "cru/base/log/Logger.h" #include #include @@ -10,7 +9,7 @@ namespace cru::platform::unix { int UnixTimerFile::GetReadFd() const { return this->read_fd_; } -UnixEventLoop::UnixEventLoop() : timer_tag_(1), polls_(1), poll_actions_(1) { +UnixEventLoop::UnixEventLoop() : polls_(1), poll_actions_(1), timer_tag_(1) { auto timer_pipe = OpenUniDirectionalPipe(UnixPipeFlags::NonBlock); timer_pipe_read_end_ = std::move(timer_pipe.read); timer_pipe_write_end_ = std::move(timer_pipe.write); @@ -19,11 +18,7 @@ UnixEventLoop::UnixEventLoop() : timer_tag_(1), polls_(1), poll_actions_(1) { poll_actions_[0] = [](auto _) {}; } -UnixEventLoop::~UnixEventLoop() { CRU_LOG_TAG_DEBUG("Event loop destroyed."); } - int UnixEventLoop::Run() { - CRU_LOG_TAG_DEBUG("Event loop started."); - running_thread_ = std::this_thread::get_id(); while (!exit_code_) { @@ -135,8 +130,6 @@ bool UnixEventLoop::CheckTimer() { return false; } - CRU_LOG_TAG_INFO("A timer is to be executed."); - auto &timer = *iter; if (timer.repeat) { while (timer.timeout <= std::chrono::milliseconds::zero()) { @@ -156,7 +149,7 @@ bool UnixEventLoop::ReadTimerPipe() { TimerData *pointer; constexpr size_t pointer_size = sizeof(decltype(pointer)); auto rest = pointer_size; - while (true) { + while (rest > 0) { auto result = timer_pipe_read_end_.Read(&pointer, rest); if (result == -1) { // If no data. @@ -178,8 +171,6 @@ bool UnixEventLoop::ReadTimerPipe() { timers_.push_back(std::move(*pointer)); delete pointer; - CRU_LOG_TAG_INFO("A timer from pipe is received."); - return true; } -- cgit v1.2.3