aboutsummaryrefslogtreecommitdiff
path: root/include/cru/base/platform/unix/EventLoop.h
diff options
context:
space:
mode:
authorYuqian Yang <crupest@crupest.life>2025-09-05 23:52:33 +0800
committerYuqian Yang <crupest@crupest.life>2025-09-05 23:52:33 +0800
commit227118866190a7fe17b42e8c589c475781c69f33 (patch)
tree0f97183ebc7de6c8e00771ce3957f4b08d5bb012 /include/cru/base/platform/unix/EventLoop.h
parent79fda9ada7878afef263f4786fd3967ec6dbfdc7 (diff)
downloadcru-227118866190a7fe17b42e8c589c475781c69f33.tar.gz
cru-227118866190a7fe17b42e8c589c475781c69f33.tar.bz2
cru-227118866190a7fe17b42e8c589c475781c69f33.zip
Event loop poll.
Diffstat (limited to 'include/cru/base/platform/unix/EventLoop.h')
-rw-r--r--include/cru/base/platform/unix/EventLoop.h16
1 files changed, 12 insertions, 4 deletions
diff --git a/include/cru/base/platform/unix/EventLoop.h b/include/cru/base/platform/unix/EventLoop.h
index b735ef26..784cb780 100644
--- a/include/cru/base/platform/unix/EventLoop.h
+++ b/include/cru/base/platform/unix/EventLoop.h
@@ -1,6 +1,5 @@
#pragma once
-#include <optional>
#if !defined(__unix) && !defined(__APPLE__)
#error "This file can only be included on unix."
#endif
@@ -9,9 +8,12 @@
#include "../../Exception.h"
#include "UnixFile.h"
+#include <poll.h>
#include <unistd.h>
#include <chrono>
+#include <optional>
#include <thread>
+#include <utility>
namespace cru::platform::unix {
class UnixTimerFile : public Object2 {
@@ -84,13 +86,19 @@ class UnixEventLoop : public Object2 {
action(std::move(action)) {}
};
-private:
+ private:
+ bool CheckPoll();
+ bool CheckTimer();
bool ReadTimerPipe();
-private:
-
+ private:
std::thread::id running_thread_;
+ std::vector<pollfd> polls_;
+ std::vector<
+ std::function<void(decltype(std::declval<pollfd>().revents) revent)>>
+ poll_actions_;
+
std::atomic_int timer_tag_;
std::vector<TimerData> timers_;