Skip to content

Commit

Permalink
reschedule coroutines mostly to secondary queue
Browse files Browse the repository at this point in the history
That fixes #3582
  • Loading branch information
klirichek committed Jun 8, 2023
1 parent 807b8cb commit 217e6b8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
18 changes: 9 additions & 9 deletions src/coroutine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ class Worker_c : public details::SchedulerOperation_t
ResetRunningAndReschedule();
}

inline void Schedule(bool bVip=true) noexcept
inline void Schedule(bool bVip=false) noexcept
{
LOG ( DEBUGV, COROW ) << "Coro::Worker_c::Schedule (" << bVip << ", " << m_pScheduler << ")";
assert ( m_pScheduler );
Expand Down Expand Up @@ -327,15 +327,15 @@ class Worker_c : public details::SchedulerOperation_t
// May refer to parent's task info as read-only. For changes has dedicated mini info, also can create and use it's own local.
static void StartOther ( Handler fnHandler, Scheduler_i * pScheduler, size_t iStack, Waiter_t tWait )
{
( new Worker_c ( myinfo::OwnMini ( std::move ( fnHandler ) ), pScheduler, std::move ( tWait ), iStack ) )->Schedule ( false );
( new Worker_c ( myinfo::OwnMini ( std::move ( fnHandler ) ), pScheduler, std::move ( tWait ), iStack ) )->Schedule ();
}

// invoked from CallCoroutine -> ReplicationStart on daemon startup. Schedule into primary queue.
// Adopt parent's task info (if any), and may change it exclusively.
// Parent thread at the moment blocked and may display info about it
static void StartCall ( Handler fnHandler, Scheduler_i* pScheduler, Waiter_t tWait )
{
( new Worker_c ( myinfo::StickParent ( std::move ( fnHandler ) ), pScheduler, std::move ( tWait ) ) )->Schedule ();
( new Worker_c ( myinfo::StickParent ( std::move ( fnHandler ) ), pScheduler, std::move ( tWait ) ) )->Schedule ( true );
}

// from Coro::Continue -> all continuations (main purpose - continue with extended stack).
Expand Down Expand Up @@ -376,15 +376,15 @@ class Worker_c : public details::SchedulerOperation_t
ScheduleContinuation();
}

inline void Pause() noexcept
inline void Pause ( bool bVip = true ) noexcept
{
if ( ( m_tState.SetFlags ( CoroState_t::Running_e | CoroState_t::Paused_e ) & CoroState_t::Running_e ) == 0 )
Schedule();
Schedule ( bVip );
}

inline void Reschedule () noexcept
inline void Reschedule ( bool bVip = true ) noexcept
{
Pause();
Pause ( bVip );
Yield_();
m_tState.ResetFlags ( CoroState_t::Paused_e );
}
Expand Down Expand Up @@ -844,10 +844,10 @@ int64_t GetThrottlingPeriodUS ()
return Worker()->GetTimePeriodUS ();
}

void RescheduleAndKeepCrashQuery()
void RescheduleAndKeepCrashQuery ( bool bVip ) noexcept
{
CrashQueryKeeper_c _;
Coro::Worker()->Reschedule(); // timer will be automatically re-engaged on resume
Coro::Worker()->Reschedule ( bVip ); // timer will be automatically re-engaged on resume
}

inline void fnResume ( volatile Worker_c* pCtx )
Expand Down
6 changes: 3 additions & 3 deletions src/coroutine.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,15 +261,15 @@ bool RuntimeExceeded() noexcept;
const int64_t& GetNextTimePointUS() noexcept;

// common throttle action - keep crash query and reschedule. Timer will be re-engaged on resume
void RescheduleAndKeepCrashQuery();
void RescheduleAndKeepCrashQuery ( bool bVip = false ) noexcept;

// just re-engage timer, without rescheduling
void RestartRuntime() noexcept;

inline void ThrottleAndKeepCrashQuery()
inline void ThrottleAndKeepCrashQuery ( bool bVip = false ) noexcept
{
if ( RuntimeExceeded() )
RescheduleAndKeepCrashQuery();
RescheduleAndKeepCrashQuery ( bVip );
}

// yield and reschedule after given period of time (in milliseconds)
Expand Down
2 changes: 1 addition & 1 deletion src/threadutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1672,9 +1672,9 @@ bool Threads::Create ( SphThread_t * pThread, Handler fnRun, bool bDetached, con


namespace { // static func
thread_local CrashQuery_t* pTlsCrashQuery = nullptr;
CrashQuery_t** g_ppTlsCrashQuery ()
{
static thread_local CrashQuery_t* pTlsCrashQuery = nullptr;
return &pTlsCrashQuery;
}

Expand Down

0 comments on commit 217e6b8

Please sign in to comment.