Check wq length before trying to steal

上级 92624e13
...@@ -41,10 +41,15 @@ void ...@@ -41,10 +41,15 @@ void
wq::dump(void) wq::dump(void)
{ {
int i; int i;
for (i = 0; i < NCPU; i++) for (i = 0; i < NCPU; i++) {
xprintf("push %lu full %lu pop %lu steal %lu\n", xprintf("push %lu full %lu pop %lu steal %lu\n",
stat_[i].push, stat_[i].full, stat_[i].push, stat_[i].full,
stat_[i].pop, stat_[i].steal); stat_[i].pop, stat_[i].steal);
stat_[i].push = 0;
stat_[i].full = 0;
stat_[i].pop = 0;
stat_[i].steal = 0;
}
} }
inline void inline void
...@@ -120,12 +125,16 @@ wq::steal(int c) ...@@ -120,12 +125,16 @@ wq::steal(int c)
work *w; work *w;
int i; int i;
i = q->tail;
if ((i - q->head) == 0)
return nullptr;
if (wqlock_tryacquire(&q->lock) == 0) if (wqlock_tryacquire(&q->lock) == 0)
return 0; return nullptr;
i = q->tail; i = q->tail;
if ((i - q->head) == 0) { if ((i - q->head) == 0) {
wqlock_release(&q->lock); wqlock_release(&q->lock);
return 0; return nullptr;
} }
i = i & (NSLOTS-1); i = i & (NSLOTS-1);
w = q->w[i]; w = q->w[i];
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论