diff options
author | Devtools Arcadia <arcadia-devtools@yandex-team.ru> | 2022-02-07 18:08:42 +0300 |
---|---|---|
committer | Devtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net> | 2022-02-07 18:08:42 +0300 |
commit | 1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch) | |
tree | e26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/cpp/coroutine/engine/cont_poller.cpp | |
download | ydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/coroutine/engine/cont_poller.cpp')
-rw-r--r-- | library/cpp/coroutine/engine/cont_poller.cpp | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/library/cpp/coroutine/engine/cont_poller.cpp b/library/cpp/coroutine/engine/cont_poller.cpp new file mode 100644 index 0000000000..76593d4e9b --- /dev/null +++ b/library/cpp/coroutine/engine/cont_poller.cpp @@ -0,0 +1,70 @@ +#include "cont_poller.h" +#include "impl.h" + +namespace NCoro { + namespace { + template <class T> + int DoExecuteEvent(T* event) noexcept { + auto* cont = event->Cont(); + + if (cont->Cancelled()) { + return ECANCELED; + } + + cont->Executor()->ScheduleIoWait(event); + cont->Switch(); + + if (cont->Cancelled()) { + return ECANCELED; + } + + return event->Status(); + } + } + + void TContPollEvent::Wake() noexcept { + UnLink(); + Cont()->ReSchedule(); + } + + + TInstant TEventWaitQueue::WakeTimedout(TInstant now) noexcept { + TIoWait::TIterator it = IoWait_.Begin(); + + if (it != IoWait_.End()) { + if (it->DeadLine() > now) { + return it->DeadLine(); + } + + do { + (it++)->Wake(ETIMEDOUT); + } while (it != IoWait_.End() && it->DeadLine() <= now); + } + + return now; + } + + void TEventWaitQueue::Register(NCoro::TContPollEvent* event) { + IoWait_.Insert(event); + event->Cont()->Unlink(); + } + + void TEventWaitQueue::Abort() noexcept { + auto visitor = [](TContPollEvent& e) { + e.Cont()->Cancel(); + }; + IoWait_.ForEach(visitor); + } +} + +void TFdEvent::RemoveFromIOWait() noexcept { + this->Cont()->Executor()->Poller()->Remove(this); +} + +int ExecuteEvent(TFdEvent* event) noexcept { + return NCoro::DoExecuteEvent(event); +} + +int ExecuteEvent(TTimerEvent* event) noexcept { + return NCoro::DoExecuteEvent(event); +} |