From 286cc8b0122c7607e0512fa8befb9dda526a30ce Mon Sep 17 00:00:00 2001 From: Samy Al Bahra Date: Sun, 1 Jul 2012 18:18:03 -0400 Subject: [PATCH] ck_hp_stack: Add trypush/trypop variants. Regressions tests pending an update (taking a snaphot, A/C is down). --- include/ck_hp_stack.h | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/include/ck_hp_stack.h b/include/ck_hp_stack.h index aba8ac4..c4edc15 100644 --- a/include/ck_hp_stack.h +++ b/include/ck_hp_stack.h @@ -44,7 +44,14 @@ ck_hp_stack_push_mpmc(struct ck_stack *target, struct ck_stack_entry *entry) return; } -CK_CC_INLINE static void * +CK_CC_INLINE static bool +ck_hp_stack_trypush_mpmc(struct ck_stack *target, struct ck_stack_entry *entry) +{ + + return ck_stack_trypush_upmc(target, entry); +} + +CK_CC_INLINE static struct ck_stack_entry * ck_hp_stack_pop_mpmc(ck_hp_record_t *record, struct ck_stack *target) { struct ck_stack_entry *entry, *update; @@ -78,4 +85,29 @@ ck_hp_stack_pop_mpmc(ck_hp_record_t *record, struct ck_stack *target) return (entry); } +CK_CC_INLINE static bool +ck_hp_stack_trypop_mpmc(ck_hp_record_t *record, struct ck_stack *target, struct ck_stack_entry **r) +{ + struct ck_stack_entry *entry; + + entry = ck_pr_load_ptr(&target->head); + if (entry == NULL) + return false; + + ck_hp_set(record, 0, entry); + ck_pr_fence_memory(); + if (entry != ck_pr_load_ptr(&target->head)) + goto leave; + + if (ck_pr_cas_ptr_value(&target->head, entry, entry->next, &entry) == false) + goto leave; + + *r = entry; + return true; + +leave: + ck_hp_set(record, 0, NULL); + return false; +} + #endif /* _CK_HP_STACK_H */