st_thread_yield主动切换协程—SRS对StateThreads的改进与完善
作者:罗上文,微信:Loken1,公众号:FFmpeg弦外之音
待写,下面是草稿。
void st_thread_yield()
{
_st_thread_t *me = _ST_CURRENT_THREAD();
#if defined(DEBUG) && defined(DEBUG_STATS)
++_st_stat_thread_yield;
#endif
/* Check sleep queue for expired threads */
_st_vp_check_clock();
// If not thread in RunQ to yield to, ignore and continue to run.
if (_ST_RUNQ.next == &_ST_RUNQ) {
return;
}
#if defined(DEBUG) && defined(DEBUG_STATS)
++_st_stat_thread_yield2;
#endif
// Append thread to the tail of RunQ, we will back after all threads executed.
me->state = _ST_ST_RUNNABLE;
_ST_ADD_RUNQ(me);
// Yield to other threads in the RunQ.
_ST_SWITCH_CONTEXT(me);
}