From f6b6d2984157cc24ee69afb9b025b5d250a5a9ad Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 2 Sep 2016 09:27:26 -0700 Subject: Address review comments --- src/core/lib/support/mpscq.c | 11 +++++++---- src/core/lib/support/mpscq.h | 4 ++-- 2 files changed, 9 insertions(+), 6 deletions(-) (limited to 'src/core/lib/support') diff --git a/src/core/lib/support/mpscq.c b/src/core/lib/support/mpscq.c index 25b055b172..cdd6335f82 100644 --- a/src/core/lib/support/mpscq.c +++ b/src/core/lib/support/mpscq.c @@ -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; } diff --git a/src/core/lib/support/mpscq.h b/src/core/lib/support/mpscq.h index 1201edceb1..977a117952 100644 --- a/src/core/lib/support/mpscq.h +++ b/src/core/lib/support/mpscq.h @@ -41,8 +41,8 @@ // implementation from Dmitry Vyukov here: // http://www.1024cores.net/home/lock-free-algorithms/queues/intrusive-mpsc-node-based-queue -// List node (include this in a data structure and dangle the rest of the -// interesting bits off the end) +// List node (include this in a data structure at the top, and add application +// fields after it - to simulate inheritance) typedef struct gpr_mpscq_node { gpr_atm next; } gpr_mpscq_node; // Actual queue type -- cgit v1.2.3