diff options
author | Craig Tiller <ctiller@google.com> | 2015-07-13 16:25:21 -0700 |
---|---|---|
committer | Craig Tiller <ctiller@google.com> | 2015-07-13 16:25:21 -0700 |
commit | eef4c2570d7bc8dbe314403a68bff2500722c07d (patch) | |
tree | 469c9ab9a5dc48e23a5680b4bc976d59352b78e6 /src/core | |
parent | 729b35a59e46bba034fcf598c01957ce4ee8c27f (diff) |
Add a detectable edge for the first insert (so far untested)
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/support/stack_lockfree.c | 3 | ||||
-rw-r--r-- | src/core/support/stack_lockfree.h | 3 |
2 files changed, 4 insertions, 2 deletions
diff --git a/src/core/support/stack_lockfree.c b/src/core/support/stack_lockfree.c index 83a68444f5..598aa9cdf1 100644 --- a/src/core/support/stack_lockfree.c +++ b/src/core/support/stack_lockfree.c @@ -95,7 +95,7 @@ void gpr_stack_lockfree_destroy(gpr_stack_lockfree *stack) { gpr_free(stack); } -void gpr_stack_lockfree_push(gpr_stack_lockfree *stack, int entry) { +int gpr_stack_lockfree_push(gpr_stack_lockfree *stack, int entry) { lockfree_node head; lockfree_node newhead; @@ -112,6 +112,7 @@ void gpr_stack_lockfree_push(gpr_stack_lockfree *stack, int entry) { } while (!gpr_atm_rel_cas(&(stack->head.atm), head.atm, newhead.atm)); /* Use rel_cas above to make sure that entry index is set properly */ + return head.atm == INVALID_ENTRY_INDEX; } int gpr_stack_lockfree_pop(gpr_stack_lockfree *stack) { diff --git a/src/core/support/stack_lockfree.h b/src/core/support/stack_lockfree.h index 7919ef38cc..4da3572deb 100644 --- a/src/core/support/stack_lockfree.h +++ b/src/core/support/stack_lockfree.h @@ -42,7 +42,8 @@ gpr_stack_lockfree *gpr_stack_lockfree_create(int entries); void gpr_stack_lockfree_destroy(gpr_stack_lockfree *); /* Pass in a valid entry number for the next stack entry */ -void gpr_stack_lockfree_push(gpr_stack_lockfree *, int entry); +/* Returns 1 if this is the first element on the stack, 0 otherwise */ +int gpr_stack_lockfree_push(gpr_stack_lockfree *, int entry); /* Returns -1 on empty or the actual entry number */ int gpr_stack_lockfree_pop(gpr_stack_lockfree *); |