Acquire wq locks only if there might be something to do

上级 d7407c57
...@@ -118,6 +118,10 @@ __wq_pop(int c) ...@@ -118,6 +118,10 @@ __wq_pop(int c)
struct wqueue *wq = &queue[c]; struct wqueue *wq = &queue[c];
struct work *w; struct work *w;
int i; int i;
i = wq->head;
if ((i - wq->tail) == 0)
return 0;
acquire(&wq->lock); acquire(&wq->lock);
i = wq->head; i = wq->head;
...@@ -142,7 +146,8 @@ __wq_steal(int c) ...@@ -142,7 +146,8 @@ __wq_steal(int c)
struct work *w; struct work *w;
int i; int i;
acquire(&wq->lock); if (tryacquire(&wq->lock) == 0)
return 0;
i = wq->tail; i = wq->tail;
if ((i - wq->head) == 0) { if ((i - wq->head) == 0) {
release(&wq->lock); release(&wq->lock);
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论