请教一下Scheduler::next_scheduler
eVen-p opened this issue · 0 comments
eVen-p commented
请教一下SchedulerManager里面,判断 sched_num是否为2的x次方 的原因是什么呢?
以及next_scheduler()当中第三行 if (n <= ~_r) 设置这个if是出于什么考虑呢
Scheduler* next_scheduler() {
if (_s != (uint32)-1) return _scheds[atomic_inc(&_n, mo_relaxed) & _s];
uint32 n = atomic_inc(&_n, mo_relaxed);
if (n <= ~_r) return _scheds[n % _scheds.size()]; // n <= (2^32 - 1 - r)
return _scheds[now::us() % _scheds.size()];
}
uint32 _n; // index, initialized as -1
uint32 _r; // 2^32 % sched_num
uint32 _s; // _r = 0, _s = sched_num-1; _r != 0, _s = -1;
感谢赐教