提交 f0dd4e31 创建 作者: Silas Boyd-Wickizer's avatar Silas Boyd-Wickizer

Use the qlock in wq.c

上级 d8736319
...@@ -35,6 +35,8 @@ ...@@ -35,6 +35,8 @@
#include "condvar.h" #include "condvar.h"
#include "queue.h" #include "queue.h"
#include "proc.h" #include "proc.h"
#include "mtrace.h"
#include "qlock.h"
#define NSLOTS (1 << WQSHIFT) #define NSLOTS (1 << WQSHIFT)
...@@ -42,7 +44,7 @@ struct wqueue { ...@@ -42,7 +44,7 @@ struct wqueue {
struct wqthread *thread[NSLOTS]; struct wqthread *thread[NSLOTS];
volatile int head __mpalign__; volatile int head __mpalign__;
struct spinlock lock; qlock_t lock;
volatile int tail; volatile int tail;
__padout__; __padout__;
} __mpalign__; } __mpalign__;
...@@ -105,17 +107,18 @@ __wq_push(struct wqueue *q, struct wqthread *t) ...@@ -105,17 +107,18 @@ __wq_push(struct wqueue *q, struct wqthread *t)
static struct wqthread * static struct wqthread *
__wq_pop(struct wqueue *q) __wq_pop(struct wqueue *q)
{ {
struct qnode qn;
int i; int i;
acquire(&q->lock); ql_lock(&q->lock, &qn);
i = q->head; i = q->head;
if ((i - q->tail) == 0) { if ((i - q->tail) == 0) {
release(&q->lock); ql_unlock(&q->lock, &qn);
return NULL; return NULL;
} }
i = (i-1) & (NSLOTS-1); i = (i-1) & (NSLOTS-1);
q->head--; q->head--;
release(&q->lock); ql_unlock(&q->lock, &qn);
wq_stat()->pop++; wq_stat()->pop++;
return q->thread[i]; return q->thread[i];
...@@ -124,17 +127,18 @@ __wq_pop(struct wqueue *q) ...@@ -124,17 +127,18 @@ __wq_pop(struct wqueue *q)
static struct wqthread * static struct wqthread *
__wq_steal(struct wqueue *q) __wq_steal(struct wqueue *q)
{ {
struct qnode qn;
int i; int i;
acquire(&q->lock); ql_lock(&q->lock, &qn);
i = q->tail; i = q->tail;
if ((i - q->head) == 0) { if ((i - q->head) == 0) {
release(&q->lock); ql_unlock(&q->lock, &qn);
return NULL; return NULL;
} }
i = i & (NSLOTS-1); i = i & (NSLOTS-1);
q->tail++; q->tail++;
release(&q->lock); ql_unlock(&q->lock, &qn);
wq_stat()->steal++; wq_stat()->steal++;
return q->thread[i]; return q->thread[i];
...@@ -301,8 +305,7 @@ initwq(void) ...@@ -301,8 +305,7 @@ initwq(void)
{ {
int i; int i;
for (i = 0; i < NCPU; i++) { for (i = 0; i < NCPU; i++)
initlock(&queue[i].lock, "queue lock"); ql_init(&queue[i].lock, "queue lock");
}
} }
#endif // WQENABLE #endif // WQENABLE
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论