From 758eea3583b5b45dbf6fdce656bf4f0885057e24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E9=A3=8E?= Date: Fri, 21 Feb 2014 15:08:18 +0800 Subject: [PATCH] bugfix: read cap in lock --- skynet-src/skynet_mq.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/skynet-src/skynet_mq.c b/skynet-src/skynet_mq.c index da7fe170..6647d6c8 100644 --- a/skynet-src/skynet_mq.c +++ b/skynet-src/skynet_mq.c @@ -111,16 +111,18 @@ skynet_mq_handle(struct message_queue *q) { int skynet_mq_length(struct message_queue *q) { - int head, tail; + int head, tail,cap; + LOCK(q) head = q->head; tail = q->tail; + cap = q->cap; UNLOCK(q) if (head <= tail) { return tail - head; } - return tail + q->cap - head; + return tail + cap - head; } int