diff options
author | Ruslan Kovalev <ruslan.a.kovalev@gmail.com> | 2022-02-10 16:46:45 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:45 +0300 |
commit | 9123176b341b6f2658cff5132482b8237c1416c8 (patch) | |
tree | 49e222ea1c5804306084bb3ae065bb702625360f /library/cpp/coroutine/engine/cont_poller.h | |
parent | 59e19371de37995fcb36beb16cd6ec030af960bc (diff) | |
download | ydb-9123176b341b6f2658cff5132482b8237c1416c8.tar.gz |
Restoring authorship annotation for Ruslan Kovalev <ruslan.a.kovalev@gmail.com>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/coroutine/engine/cont_poller.h')
-rw-r--r-- | library/cpp/coroutine/engine/cont_poller.h | 356 |
1 files changed, 178 insertions, 178 deletions
diff --git a/library/cpp/coroutine/engine/cont_poller.h b/library/cpp/coroutine/engine/cont_poller.h index 824b05489a..b638b2df1a 100644 --- a/library/cpp/coroutine/engine/cont_poller.h +++ b/library/cpp/coroutine/engine/cont_poller.h @@ -1,245 +1,245 @@ -#pragma once +#pragma once #include "poller.h" -#include "sockmap.h" +#include "sockmap.h" #include <library/cpp/containers/intrusive_rb_tree/rb_tree.h> - -#include <util/datetime/base.h> -#include <util/memory/pool.h> + +#include <util/datetime/base.h> +#include <util/memory/pool.h> #include <util/memory/smallobj.h> -#include <util/network/init.h> +#include <util/network/init.h> + +#include <cerrno> + -#include <cerrno> - - class TCont; class TContExecutor; -class TFdEvent; +class TFdEvent; -namespace NCoro { - - class IPollEvent; +namespace NCoro { + class IPollEvent; - struct TContPollEventCompare { - template <class T> - static inline bool Compare(const T& l, const T& r) noexcept { - return l.DeadLine() < r.DeadLine() || (l.DeadLine() == r.DeadLine() && &l < &r); - } - }; - - class TContPollEvent : public TRbTreeItem<TContPollEvent, TContPollEventCompare> { - public: - TContPollEvent(TCont* cont, TInstant deadLine) noexcept - : Cont_(cont) - , DeadLine_(deadLine) - {} + struct TContPollEventCompare { + template <class T> + static inline bool Compare(const T& l, const T& r) noexcept { + return l.DeadLine() < r.DeadLine() || (l.DeadLine() == r.DeadLine() && &l < &r); + } + }; - static bool Compare(const TContPollEvent& l, const TContPollEvent& r) noexcept { - return l.DeadLine() < r.DeadLine() || (l.DeadLine() == r.DeadLine() && &l < &r); - } - int Status() const noexcept { - return Status_; - } + class TContPollEvent : public TRbTreeItem<TContPollEvent, TContPollEventCompare> { + public: + TContPollEvent(TCont* cont, TInstant deadLine) noexcept + : Cont_(cont) + , DeadLine_(deadLine) + {} - void SetStatus(int status) noexcept { - Status_ = status; - } + static bool Compare(const TContPollEvent& l, const TContPollEvent& r) noexcept { + return l.DeadLine() < r.DeadLine() || (l.DeadLine() == r.DeadLine() && &l < &r); + } - TCont* Cont() noexcept { - return Cont_; - } + int Status() const noexcept { + return Status_; + } + + void SetStatus(int status) noexcept { + Status_ = status; + } + + TCont* Cont() noexcept { + return Cont_; + } - TInstant DeadLine() const noexcept { - return DeadLine_; - } + TInstant DeadLine() const noexcept { + return DeadLine_; + } - void Wake(int status) noexcept { - SetStatus(status); - Wake(); + void Wake(int status) noexcept { + SetStatus(status); + Wake(); } - private: - void Wake() noexcept; + private: + void Wake() noexcept; - private: - TCont* Cont_; - TInstant DeadLine_; - int Status_ = EINPROGRESS; + private: + TCont* Cont_; + TInstant DeadLine_; + int Status_ = EINPROGRESS; }; - class IPollEvent: public TIntrusiveListItem<IPollEvent> { - public: - IPollEvent(SOCKET fd, ui16 what) noexcept - : Fd_(fd) - , What_(what) - {} + class IPollEvent: public TIntrusiveListItem<IPollEvent> { + public: + IPollEvent(SOCKET fd, ui16 what) noexcept + : Fd_(fd) + , What_(what) + {} + + virtual ~IPollEvent() {} - virtual ~IPollEvent() {} + SOCKET Fd() const noexcept { + return Fd_; + } - SOCKET Fd() const noexcept { - return Fd_; - } + int What() const noexcept { + return What_; + } - int What() const noexcept { - return What_; - } + virtual void OnPollEvent(int status) noexcept = 0; - virtual void OnPollEvent(int status) noexcept = 0; + private: + SOCKET Fd_; + ui16 What_; + }; - private: - SOCKET Fd_; - ui16 What_; - }; + template <class T> + class TBigArray { + struct TValue: public T, public TObjectFromPool<TValue> { + TValue() {} + }; - template <class T> - class TBigArray { - struct TValue: public T, public TObjectFromPool<TValue> { - TValue() {} - }; + public: + TBigArray() + : Pool_(TMemoryPool::TExpGrow::Instance(), TDefaultAllocator::Instance()) + {} - public: - TBigArray() - : Pool_(TMemoryPool::TExpGrow::Instance(), TDefaultAllocator::Instance()) - {} - - T* Get(size_t index) { - TRef& ret = Lst_.Get(index); - if (!ret) { + T* Get(size_t index) { + TRef& ret = Lst_.Get(index); + if (!ret) { ret = TRef(new (&Pool_) TValue()); - } - return ret.Get(); - } - - private: - using TRef = THolder<TValue>; - typename TValue::TPool Pool_; - TSocketMap<TRef> Lst_; - }; - - - using TPollEventList = TIntrusiveList<IPollEvent>; - - class TContPoller { - public: - using TEvent = IPollerFace::TEvent; - using TEvents = IPollerFace::TEvents; - - TContPoller() - : P_(IPollerFace::Default()) - { - } - - explicit TContPoller(THolder<IPollerFace> poller) - : P_(std::move(poller)) - {} - - void Schedule(IPollEvent* event) { - auto* lst = Lists_.Get(event->Fd()); - const ui16 oldFlags = Flags(*lst); - lst->PushFront(event); + } + return ret.Get(); + } + + private: + using TRef = THolder<TValue>; + typename TValue::TPool Pool_; + TSocketMap<TRef> Lst_; + }; + + + using TPollEventList = TIntrusiveList<IPollEvent>; + + class TContPoller { + public: + using TEvent = IPollerFace::TEvent; + using TEvents = IPollerFace::TEvents; + + TContPoller() + : P_(IPollerFace::Default()) + { + } + + explicit TContPoller(THolder<IPollerFace> poller) + : P_(std::move(poller)) + {} + + void Schedule(IPollEvent* event) { + auto* lst = Lists_.Get(event->Fd()); + const ui16 oldFlags = Flags(*lst); + lst->PushFront(event); ui16 newFlags = Flags(*lst); - if (newFlags != oldFlags) { + if (newFlags != oldFlags) { if (oldFlags) { newFlags |= CONT_POLL_MODIFY; } - P_->Set(lst, event->Fd(), newFlags); - } + P_->Set(lst, event->Fd(), newFlags); + } } - void Remove(IPollEvent* event) noexcept { - auto* lst = Lists_.Get(event->Fd()); - const ui16 oldFlags = Flags(*lst); - event->Unlink(); + void Remove(IPollEvent* event) noexcept { + auto* lst = Lists_.Get(event->Fd()); + const ui16 oldFlags = Flags(*lst); + event->Unlink(); ui16 newFlags = Flags(*lst); - if (newFlags != oldFlags) { + if (newFlags != oldFlags) { if (newFlags) { newFlags |= CONT_POLL_MODIFY; } - P_->Set(lst, event->Fd(), newFlags); - } + P_->Set(lst, event->Fd(), newFlags); + } } - void Wait(TEvents& events, TInstant deadLine) { - events.clear(); - P_->Wait(events, deadLine); + void Wait(TEvents& events, TInstant deadLine) { + events.clear(); + P_->Wait(events, deadLine); } EContPoller PollEngine() const { return P_->PollEngine(); } - private: - static ui16 Flags(TIntrusiveList<IPollEvent>& lst) noexcept { - ui16 ret = 0; - for (auto&& item : lst) { - ret |= item.What(); + private: + static ui16 Flags(TIntrusiveList<IPollEvent>& lst) noexcept { + ui16 ret = 0; + for (auto&& item : lst) { + ret |= item.What(); } - return ret; + return ret; } - private: - TBigArray<TPollEventList> Lists_; - THolder<IPollerFace> P_; + private: + TBigArray<TPollEventList> Lists_; + THolder<IPollerFace> P_; }; - - - class TEventWaitQueue { - using TIoWait = TRbTree<NCoro::TContPollEvent, NCoro::TContPollEventCompare>; - - public: - void Register(NCoro::TContPollEvent* event); - - bool Empty() const noexcept { - return IoWait_.Empty(); - } - - void Abort() noexcept; - - TInstant WakeTimedout(TInstant now) noexcept; - - private: - TIoWait IoWait_; - }; -} - -class TFdEvent final: - public NCoro::TContPollEvent, - public NCoro::IPollEvent -{ + + + class TEventWaitQueue { + using TIoWait = TRbTree<NCoro::TContPollEvent, NCoro::TContPollEventCompare>; + + public: + void Register(NCoro::TContPollEvent* event); + + bool Empty() const noexcept { + return IoWait_.Empty(); + } + + void Abort() noexcept; + + TInstant WakeTimedout(TInstant now) noexcept; + + private: + TIoWait IoWait_; + }; +} + +class TFdEvent final: + public NCoro::TContPollEvent, + public NCoro::IPollEvent +{ public: - TFdEvent(TCont* cont, SOCKET fd, ui16 what, TInstant deadLine) noexcept - : TContPollEvent(cont, deadLine) - , IPollEvent(fd, what) - {} - - ~TFdEvent() { - RemoveFromIOWait(); + TFdEvent(TCont* cont, SOCKET fd, ui16 what, TInstant deadLine) noexcept + : TContPollEvent(cont, deadLine) + , IPollEvent(fd, what) + {} + + ~TFdEvent() { + RemoveFromIOWait(); } - void RemoveFromIOWait() noexcept; + void RemoveFromIOWait() noexcept; - void OnPollEvent(int status) noexcept override { - Wake(status); + void OnPollEvent(int status) noexcept override { + Wake(status); } }; - -class TTimerEvent: public NCoro::TContPollEvent { + +class TTimerEvent: public NCoro::TContPollEvent { public: - TTimerEvent(TCont* cont, TInstant deadLine) noexcept - : TContPollEvent(cont, deadLine) - {} + TTimerEvent(TCont* cont, TInstant deadLine) noexcept + : TContPollEvent(cont, deadLine) + {} }; - -int ExecuteEvent(TFdEvent* event) noexcept; - -int ExecuteEvent(TTimerEvent* event) noexcept; + +int ExecuteEvent(TFdEvent* event) noexcept; + +int ExecuteEvent(TTimerEvent* event) noexcept; |