From 9bb385938ead40970b54971cf03a460df9bce4d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E9=A3=8E?= Date: Tue, 16 Oct 2012 10:23:43 +0800 Subject: [PATCH] add write barrier --- skynet-src/skynet_mq.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/skynet-src/skynet_mq.c b/skynet-src/skynet_mq.c index 9d682a41..b6f767f6 100644 --- a/skynet-src/skynet_mq.c +++ b/skynet-src/skynet_mq.c @@ -48,25 +48,28 @@ skynet_globalmq_push(struct message_queue * queue) { q->queue[tail] = queue; __sync_synchronize(); q->flag[tail] = true; + __sync_synchronize(); } struct message_queue * skynet_globalmq_pop() { struct global_queue *q = Q; - uint32_t head = q->head; - uint32_t head_ptr = GP(head); - if (head_ptr == GP(q->tail)) { - return NULL; - } - + uint32_t head = q->head; + uint32_t head_ptr = GP(head); + if (head_ptr == GP(q->tail)) { + return NULL; + } + + __sync_synchronize(); + if(!q->flag[head_ptr]) { return NULL; } - struct message_queue * mq = q->queue[head_ptr]; - if (!__sync_bool_compare_and_swap(&q->head, head, head+1)) { - return NULL; - } + struct message_queue * mq = q->queue[head_ptr]; + if (!__sync_bool_compare_and_swap(&q->head, head, head+1)) { + return NULL; + } q->flag[head_ptr] = false; return mq;