mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-25 12:43:09 +00:00
add write barrier
This commit is contained in:
@@ -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;
|
||||||
|
|||||||
Reference in New Issue
Block a user