From 8ae794332b3aef97e63811ecb9007b9cd5fc538e Mon Sep 17 00:00:00 2001 From: "keldu.magnus" Date: Wed, 2 Sep 2020 16:50:42 +0200 Subject: [PATCH] added wait functionality --- driver/io-unix.h | 2 ++ source/async.cpp | 35 ++++++++++++++++++++++++++++++++--- source/async.h | 1 + 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/driver/io-unix.h b/driver/io-unix.h index fc9ce07..203b5ca 100644 --- a/driver/io-unix.h +++ b/driver/io-unix.h @@ -183,6 +183,8 @@ public: void poll() override { pollImpl(0); } + void wait() override { pollImpl(-1); } + void subscribe(IFdOwner &owner, int fd, uint32_t event_mask) { if (epoll_fd < 0 || fd < 0) { return; diff --git a/source/async.cpp b/source/async.cpp index 9a2d273..32a6a73 100644 --- a/source/async.cpp +++ b/source/async.cpp @@ -181,14 +181,43 @@ bool EventLoop::turn() { } bool EventLoop::wait(const std::chrono::steady_clock::duration &duration) { - return false; + if (event_port) { + event_port->wait(); + } + + while (head) { + if (!turn()) { + return false; + } + } + return true; } bool EventLoop::wait(const std::chrono::steady_clock::time_point &time_point) { - return false; + if (event_port) { + event_port->wait(); + } + + while (head) { + if (!turn()) { + return false; + } + } + return true; } -bool EventLoop::wait() { return false; } +bool EventLoop::wait() { + if (event_port) { + event_port->wait(); + } + + while (head) { + if (!turn()) { + return false; + } + } + return true; +} bool EventLoop::poll() { if (event_port) { diff --git a/source/async.h b/source/async.h index 847305f..03efdc5 100644 --- a/source/async.h +++ b/source/async.h @@ -173,6 +173,7 @@ public: virtual Conveyor onSignal(Signal signal) = 0; virtual void poll() = 0; + virtual void wait() = 0; }; class SinkConveyorNode;