added a switch count to coroutine to prevent long runs of a single coroutine
@@ -211,6 +211,7 @@ public:
, Func_(func)
, Arg_(arg)
, Name_(name)
+ , SwitchCount_(0)
, Cancelled_(false)
, Scheduled_(false)
{
@@ -225,7 +226,10 @@ public:
inline void SwitchTo(TCont* next) noexcept {
DBGOUT(PCORO(this) << " switch to " << PCORO(next));
-
+ if (next == this) {
+ return;
+ }
+ SwitchCount_ += 1;
Context()->SwitchTo(next->Context());
}
@@ -261,6 +265,10 @@ public:
return Name_;
}
+ inline ui64 GetSwitchCount() const noexcept {
+ return SwitchCount_;
+ }
+
void PrintMe(IOutputStream& out) const noexcept;
inline void Yield() noexcept {
@@ -479,6 +487,7 @@ private:
void* Arg_;
const char* Name_;
TIntrusiveList<TJoinWait> Waiters_;
+ ui64 SwitchCount_;
bool Cancelled_;
bool Scheduled_;
};
