aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/coroutine/engine
diff options
context:
space:
mode:
authornocomer <nocomer@yandex-team.com>2022-12-07 17:37:14 +0300
committernocomer <nocomer@yandex-team.com>2022-12-07 17:37:14 +0300
commit073cfa733cd8ec817135f28cb8a2719452094d73 (patch)
tree5be69eaa31ee3bb9ed540c8aaca8177941597847 /library/cpp/coroutine/engine
parent37030c245fe253ac59f915e72acb74d5e677cca0 (diff)
downloadydb-073cfa733cd8ec817135f28cb8a2719452094d73.tar.gz
Improve error handling: add counters for internal, other and because of ban errors/fails, provide source of errors and reasons of coroutine cancellations
Diffstat (limited to 'library/cpp/coroutine/engine')
-rw-r--r--library/cpp/coroutine/engine/impl.cpp10
-rw-r--r--library/cpp/coroutine/engine/impl.h19
2 files changed, 20 insertions, 9 deletions
diff --git a/library/cpp/coroutine/engine/impl.cpp b/library/cpp/coroutine/engine/impl.cpp
index 08f358127d..ac116af0c1 100644
--- a/library/cpp/coroutine/engine/impl.cpp
+++ b/library/cpp/coroutine/engine/impl.cpp
@@ -41,14 +41,18 @@ void TCont::PrintMe(IOutputStream& out) const noexcept {
<< ")";
}
-bool TCont::Join(TCont* c, TInstant deadLine) noexcept {
+bool TCont::Join(TCont* c, TInstant deadLine, std::function<void(TJoinWait&, TCont*)> forceStop) noexcept {
TJoinWait ev(*this);
c->Waiters_.PushBack(&ev);
do {
if (SleepD(deadLine) == ETIMEDOUT || Cancelled()) {
if (!ev.Empty()) {
- c->Cancel();
+ if (forceStop) {
+ forceStop(ev, c);
+ } else {
+ c->Cancel();
+ }
do {
Switch();
@@ -108,7 +112,7 @@ void TCont::Cancel() noexcept {
void TCont::Cancel(THolder<std::exception> exception) noexcept {
if (!Cancelled()) {
- Exception_ = std::move(exception);
+ SetException(std::move(exception));
Cancel();
}
}
diff --git a/library/cpp/coroutine/engine/impl.h b/library/cpp/coroutine/engine/impl.h
index ca523cdaf3..ec4af17fcf 100644
--- a/library/cpp/coroutine/engine/impl.h
+++ b/library/cpp/coroutine/engine/impl.h
@@ -30,6 +30,12 @@ namespace NCoro::NStack {
}
class TCont : private TIntrusiveListItem<TCont> {
+ friend class TContExecutor;
+ friend class TIntrusiveListItem<TCont>;
+ friend class NCoro::TEventWaitQueue;
+ friend class NCoro::TTrampoline;
+
+public:
struct TJoinWait: public TIntrusiveListItem<TJoinWait> {
TJoinWait(TCont& c) noexcept;
@@ -39,11 +45,6 @@ class TCont : private TIntrusiveListItem<TCont> {
TCont& Cont_;
};
- friend class TContExecutor;
- friend class TIntrusiveListItem<TCont>;
- friend class NCoro::TEventWaitQueue;
- friend class NCoro::TTrampoline;
-
private:
TCont(
NCoro::NStack::IAllocator& allocator,
@@ -99,7 +100,9 @@ public:
/// \param this корутина, которая будет ждать
/// \param c корутина, которую будем ждать
/// \param deadLine максимальное время ожидания
- bool Join(TCont* c, TInstant deadLine = TInstant::Max()) noexcept;
+ /// \param forceStop кастомный обработчик ситуации, когда завершается время ожидания или отменяется ожидающая корутина (this)
+ /// дефолтное поведение - отменить ожидаемую корутину (c->Cancel())
+ bool Join(TCont* c, TInstant deadLine = TInstant::Max(), std::function<void(TJoinWait&, TCont*)> forceStop = {}) noexcept;
void ReSchedule() noexcept;
@@ -113,6 +116,10 @@ public:
return std::move(Exception_);
}
+ void SetException(THolder<std::exception> exception) noexcept {
+ Exception_ = std::move(exception);
+ }
+
private:
void Terminate();