add write barrier

This commit is contained in:
云风
2012-10-16 10:23:43 +08:00
parent 115d9d9e2d
commit 9bb385938e

View File

@@ -48,25 +48,28 @@ skynet_globalmq_push(struct message_queue * queue) {
q->queue[tail] = queue; q->queue[tail] = queue;
__sync_synchronize(); __sync_synchronize();
q->flag[tail] = true; q->flag[tail] = true;
__sync_synchronize();
} }
struct message_queue * struct message_queue *
skynet_globalmq_pop() { skynet_globalmq_pop() {
struct global_queue *q = Q; struct global_queue *q = Q;
uint32_t head = q->head; uint32_t head = q->head;
uint32_t head_ptr = GP(head); uint32_t head_ptr = GP(head);
if (head_ptr == GP(q->tail)) { if (head_ptr == GP(q->tail)) {
return NULL; return NULL;
} }
__sync_synchronize();
if(!q->flag[head_ptr]) { if(!q->flag[head_ptr]) {
return NULL; return NULL;
} }
struct message_queue * mq = q->queue[head_ptr]; struct message_queue * mq = q->queue[head_ptr];
if (!__sync_bool_compare_and_swap(&q->head, head, head+1)) { if (!__sync_bool_compare_and_swap(&q->head, head, head+1)) {
return NULL; return NULL;
} }
q->flag[head_ptr] = false; q->flag[head_ptr] = false;
return mq; return mq;