aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/coroutine/engine/events.h
diff options
context:
space:
mode:
authorAnton Samokhvalov <pg83@yandex.ru>2022-02-10 16:45:15 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:45:15 +0300
commit72cb13b4aff9bc9cf22e49251bc8fd143f82538f (patch)
treeda2c34829458c7d4e74bdfbdf85dff449e9e7fb8 /library/cpp/coroutine/engine/events.h
parent778e51ba091dc39e7b7fcab2b9cf4dbedfb6f2b5 (diff)
downloadydb-72cb13b4aff9bc9cf22e49251bc8fd143f82538f.tar.gz
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/coroutine/engine/events.h')
-rw-r--r--library/cpp/coroutine/engine/events.h216
1 files changed, 108 insertions, 108 deletions
diff --git a/library/cpp/coroutine/engine/events.h b/library/cpp/coroutine/engine/events.h
index 07cc4d25e8..2e879999bf 100644
--- a/library/cpp/coroutine/engine/events.h
+++ b/library/cpp/coroutine/engine/events.h
@@ -1,148 +1,148 @@
#pragma once
-
+
#include "impl.h"
#include <util/datetime/base.h>
-class TContEvent {
-public:
+class TContEvent {
+public:
TContEvent(TCont* current) noexcept
- : Cont_(current)
- , Status_(0)
- {
- }
-
+ : Cont_(current)
+ , Status_(0)
+ {
+ }
+
~TContEvent() {
- }
-
+ }
+
int WaitD(TInstant deadline) {
- Status_ = 0;
- const int ret = Cont_->SleepD(deadline);
-
- return Status_ ? Status_ : ret;
- }
-
+ Status_ = 0;
+ const int ret = Cont_->SleepD(deadline);
+
+ return Status_ ? Status_ : ret;
+ }
+
int WaitT(TDuration timeout) {
- return WaitD(timeout.ToDeadLine());
- }
-
+ return WaitD(timeout.ToDeadLine());
+ }
+
int WaitI() {
- return WaitD(TInstant::Max());
- }
-
+ return WaitD(TInstant::Max());
+ }
+
void Wake() noexcept {
- SetStatus(EWAKEDUP);
- Cont_->ReSchedule();
- }
-
+ SetStatus(EWAKEDUP);
+ Cont_->ReSchedule();
+ }
+
TCont* Cont() noexcept {
- return Cont_;
- }
-
+ return Cont_;
+ }
+
int Status() const noexcept {
- return Status_;
- }
-
+ return Status_;
+ }
+
void SetStatus(int status) noexcept {
- Status_ = status;
- }
-
-private:
- TCont* Cont_;
- int Status_;
-};
-
-class TContWaitQueue {
- class TWaiter: public TContEvent, public TIntrusiveListItem<TWaiter> {
- public:
+ Status_ = status;
+ }
+
+private:
+ TCont* Cont_;
+ int Status_;
+};
+
+class TContWaitQueue {
+ class TWaiter: public TContEvent, public TIntrusiveListItem<TWaiter> {
+ public:
TWaiter(TCont* current) noexcept
- : TContEvent(current)
- {
- }
-
+ : TContEvent(current)
+ {
+ }
+
~TWaiter() {
- }
- };
-
-public:
+ }
+ };
+
+public:
TContWaitQueue() noexcept {
- }
-
+ }
+
~TContWaitQueue() {
Y_ASSERT(Waiters_.Empty());
- }
-
+ }
+
int WaitD(TCont* current, TInstant deadline) {
- TWaiter waiter(current);
-
- Waiters_.PushBack(&waiter);
-
- return waiter.WaitD(deadline);
- }
-
+ TWaiter waiter(current);
+
+ Waiters_.PushBack(&waiter);
+
+ return waiter.WaitD(deadline);
+ }
+
int WaitT(TCont* current, TDuration timeout) {
- return WaitD(current, timeout.ToDeadLine());
- }
-
+ return WaitD(current, timeout.ToDeadLine());
+ }
+
int WaitI(TCont* current) {
- return WaitD(current, TInstant::Max());
- }
-
+ return WaitD(current, TInstant::Max());
+ }
+
void Signal() noexcept {
- if (!Waiters_.Empty()) {
- Waiters_.PopFront()->Wake();
- }
- }
+ if (!Waiters_.Empty()) {
+ Waiters_.PopFront()->Wake();
+ }
+ }
void BroadCast() noexcept {
- while (!Waiters_.Empty()) {
- Waiters_.PopFront()->Wake();
- }
- }
-
+ while (!Waiters_.Empty()) {
+ Waiters_.PopFront()->Wake();
+ }
+ }
+
void BroadCast(size_t number) noexcept {
for (size_t i = 0; i < number && !Waiters_.Empty(); ++i) {
Waiters_.PopFront()->Wake();
}
}
-private:
- TIntrusiveList<TWaiter> Waiters_;
-};
-
+private:
+ TIntrusiveList<TWaiter> Waiters_;
+};
+
-class TContSimpleEvent {
-public:
+class TContSimpleEvent {
+public:
TContSimpleEvent(TContExecutor* e)
- : E_(e)
- {
- }
-
+ : E_(e)
+ {
+ }
+
TContExecutor* Executor() const noexcept {
- return E_;
- }
-
+ return E_;
+ }
+
void Signal() noexcept {
- Q_.Signal();
- }
-
+ Q_.Signal();
+ }
+
void BroadCast() noexcept {
- Q_.BroadCast();
- }
-
+ Q_.BroadCast();
+ }
+
int WaitD(TInstant deadLine) noexcept {
return Q_.WaitD(E_->Running(), deadLine);
- }
-
+ }
+
int WaitT(TDuration timeout) noexcept {
- return WaitD(timeout.ToDeadLine());
- }
-
+ return WaitD(timeout.ToDeadLine());
+ }
+
int WaitI() noexcept {
- return WaitD(TInstant::Max());
- }
-
-private:
- TContWaitQueue Q_;
- TContExecutor* E_;
-};
+ return WaitD(TInstant::Max());
+ }
+
+private:
+ TContWaitQueue Q_;
+ TContExecutor* E_;
+};