Skip to content

Commit

Permalink
Insert at the head of RunQ, to execute timer first.
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Feb 11, 2021
1 parent a789c98 commit 9fe8cfe
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ extern _st_eventsys_t *_st_eventsys;
#define _ST_DEL_IOQ(_pq) ST_REMOVE_LINK(&_pq.links)

#define _ST_ADD_RUNQ(_thr) ST_APPEND_LINK(&(_thr)->links, &_ST_RUNQ)
#define _ST_INSERT_RUNQ(_thr) ST_INSERT_LINK(&(_thr)->links, &_ST_RUNQ)
#define _ST_DEL_RUNQ(_thr) ST_REMOVE_LINK(&(_thr)->links)

#define _ST_ADD_SLEEPQ(_thr, _timeout) _st_add_sleep_q(_thr, _timeout)
Expand Down
3 changes: 2 additions & 1 deletion sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,8 @@ void _st_vp_check_clock(void)
/* Make thread runnable */
ST_ASSERT(!(thread->flags & _ST_FL_IDLE_THREAD));
thread->state = _ST_ST_RUNNABLE;
_ST_ADD_RUNQ(thread);
// Insert at the head of RunQ, to execute timer first.
_ST_INSERT_RUNQ(thread);
}
}

Expand Down

2 comments on commit 9fe8cfe

@winlinvip
Copy link
Member Author

@winlinvip winlinvip commented on 9fe8cfe Feb 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

调整timer协程的优先级,放到运行队列的头部,即首先执行timer。参考:ossrs/srs#2194

@winlinvip
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以做得更好的是:设置协程的优先级,高优先级的放头部,一般优先级的放尾部。

Please sign in to comment.