|
|
|
@ -38,7 +38,7 @@ |
|
|
|
|
void gpr_mpscq_init(gpr_mpscq *q) { |
|
|
|
|
gpr_atm_no_barrier_store(&q->head, (gpr_atm)&q->stub); |
|
|
|
|
q->tail = &q->stub; |
|
|
|
|
gpr_atm_no_barrier_store(&q->stub.next, 0); |
|
|
|
|
gpr_atm_no_barrier_store(&q->stub.next, (gpr_atm)NULL); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void gpr_mpscq_destroy(gpr_mpscq *q) { |
|
|
|
@ -47,16 +47,17 @@ void gpr_mpscq_destroy(gpr_mpscq *q) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void gpr_mpscq_push(gpr_mpscq *q, gpr_mpscq_node *n) { |
|
|
|
|
gpr_atm_no_barrier_store(&n->next, 0); |
|
|
|
|
gpr_atm_no_barrier_store(&n->next, (gpr_atm)NULL); |
|
|
|
|
gpr_mpscq_node *prev = |
|
|
|
|
(gpr_mpscq_node *)gpr_atm_full_xchg(&q->head, (gpr_atm)n); |
|
|
|
|
gpr_atm_rel_store(&prev->next, (gpr_atm)n); |
|
|
|
|
gpr_atm_no_barrier_store(&prev->next, (gpr_atm)n); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
gpr_mpscq_node *gpr_mpscq_pop(gpr_mpscq *q) { |
|
|
|
|
gpr_mpscq_node *tail = q->tail; |
|
|
|
|
gpr_mpscq_node *next = (gpr_mpscq_node *)gpr_atm_acq_load(&tail->next); |
|
|
|
|
if (tail == &q->stub) { |
|
|
|
|
// indicates the list is actually (ephemerally) empty
|
|
|
|
|
if (next == NULL) return NULL; |
|
|
|
|
q->tail = next; |
|
|
|
|
tail = next; |
|
|
|
@ -68,7 +69,8 @@ gpr_mpscq_node *gpr_mpscq_pop(gpr_mpscq *q) { |
|
|
|
|
} |
|
|
|
|
gpr_mpscq_node *head = (gpr_mpscq_node *)gpr_atm_acq_load(&q->head); |
|
|
|
|
if (tail != head) { |
|
|
|
|
return 0; |
|
|
|
|
// indicates a retry is in order: we're still adding
|
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
gpr_mpscq_push(q, &q->stub); |
|
|
|
|
next = (gpr_mpscq_node *)gpr_atm_acq_load(&tail->next); |
|
|
|
@ -76,5 +78,6 @@ gpr_mpscq_node *gpr_mpscq_pop(gpr_mpscq *q) { |
|
|
|
|
q->tail = next; |
|
|
|
|
return tail; |
|
|
|
|
} |
|
|
|
|
// indicates a retry is in order: we're still adding
|
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|