bugfix: read cap in lock

This commit is contained in:
云风
2014-02-21 15:08:18 +08:00
parent 46febacbb9
commit 758eea3583

View File

@@ -111,16 +111,18 @@ skynet_mq_handle(struct message_queue *q) {
int int
skynet_mq_length(struct message_queue *q) { skynet_mq_length(struct message_queue *q) {
int head, tail; int head, tail,cap;
LOCK(q) LOCK(q)
head = q->head; head = q->head;
tail = q->tail; tail = q->tail;
cap = q->cap;
UNLOCK(q) UNLOCK(q)
if (head <= tail) { if (head <= tail) {
return tail - head; return tail - head;
} }
return tail + q->cap - head; return tail + cap - head;
} }
int int