aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/lib/support
diff options
context:
space:
mode:
authorGravatar Craig Tiller <ctiller@google.com>2016-09-02 09:30:26 -0700
committerGravatar Craig Tiller <ctiller@google.com>2016-09-02 09:30:26 -0700
commit57ceb42df03058806a377dbe07f5951ee511da0f (patch)
tree89d4e3d920311c89e48cba9721f42953e6c0e9ba /src/core/lib/support
parent39b9914d850e856ae5a3e22ab2972b746229ce2a (diff)
parent56f21aa79c794cad614bec30702e6c5ff3922518 (diff)
Merge branch 'who-combines-the-combiners' into direct-calls
Diffstat (limited to 'src/core/lib/support')
-rw-r--r--src/core/lib/support/mpscq.c11
-rw-r--r--src/core/lib/support/mpscq.h4
2 files changed, 9 insertions, 6 deletions
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