|
|
|
@ -65,6 +65,24 @@ ck_stack_push_upmc(struct ck_stack *target, struct ck_stack_entry *entry)
|
|
|
|
|
}
|
|
|
|
|
#endif /* CK_F_STACK_PUSH_UPMC */
|
|
|
|
|
|
|
|
|
|
#ifndef CK_F_STACK_TRYPUSH_UPMC
|
|
|
|
|
#define CK_F_STACK_TRYPUSH_UPMC
|
|
|
|
|
/*
|
|
|
|
|
* Stack producer operation for multiple unique producers and multiple consumers.
|
|
|
|
|
* Returns true on success and false on failure.
|
|
|
|
|
*/
|
|
|
|
|
CK_CC_INLINE static bool
|
|
|
|
|
ck_stack_trypush_upmc(struct ck_stack *target, struct ck_stack_entry *entry)
|
|
|
|
|
{
|
|
|
|
|
struct ck_stack_entry *stack;
|
|
|
|
|
|
|
|
|
|
stack = ck_pr_load_ptr(&target->head);
|
|
|
|
|
ck_pr_store_ptr(&entry->next, stack);
|
|
|
|
|
|
|
|
|
|
return ck_pr_cas_ptr(&target->head, stack, entry);
|
|
|
|
|
}
|
|
|
|
|
#endif /* CK_F_STACK_TRYPUSH_UPMC */
|
|
|
|
|
|
|
|
|
|
#ifndef CK_F_STACK_POP_UPMC
|
|
|
|
|
#define CK_F_STACK_POP_UPMC
|
|
|
|
|
/*
|
|
|
|
@ -88,6 +106,32 @@ ck_stack_pop_upmc(struct ck_stack *target)
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef CK_F_STACK_TRYPOP_UPMC
|
|
|
|
|
#define CK_F_STACK_TRYPOP_UPMC
|
|
|
|
|
/*
|
|
|
|
|
* Stack production operation for multiple unique producers and multiple consumers.
|
|
|
|
|
* Returns true on success and false on failure. The value pointed to by the second
|
|
|
|
|
* argument is set to a valid ck_stack_entry_t reference if true is returned. If
|
|
|
|
|
* false is returned, then the value pointed to by the second argument is undefined.
|
|
|
|
|
*/
|
|
|
|
|
CK_CC_INLINE static bool
|
|
|
|
|
ck_stack_trypop_upmc(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;
|
|
|
|
|
|
|
|
|
|
if (ck_pr_cas_ptr(&target->head, entry, entry->next) == true) {
|
|
|
|
|
*r = entry;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
#endif /* CK_F_STACK_TRYPOP_UPMC */
|
|
|
|
|
|
|
|
|
|
#ifndef CK_F_STACK_BATCH_POP_UPMC
|
|
|
|
|
#define CK_F_STACK_BATCH_POP_UPMC
|
|
|
|
|
/*
|
|
|
|
@ -117,6 +161,19 @@ ck_stack_push_mpmc(struct ck_stack *target, struct ck_stack_entry *entry)
|
|
|
|
|
}
|
|
|
|
|
#endif /* CK_F_STACK_PUSH_MPMC */
|
|
|
|
|
|
|
|
|
|
#ifndef CK_F_STACK_TRYPUSH_MPMC
|
|
|
|
|
#define CK_F_STACK_TRYPUSH_MPMC
|
|
|
|
|
/*
|
|
|
|
|
* Stack producer operation safe for multiple producers and multiple consumers.
|
|
|
|
|
*/
|
|
|
|
|
CK_CC_INLINE static bool
|
|
|
|
|
ck_stack_trypush_mpmc(struct ck_stack *target, struct ck_stack_entry *entry)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
return ck_stack_trypush_upmc(target, entry);
|
|
|
|
|
}
|
|
|
|
|
#endif /* CK_F_STACK_TRYPUSH_MPMC */
|
|
|
|
|
|
|
|
|
|
#ifdef CK_F_PR_CAS_PTR_2_VALUE
|
|
|
|
|
#ifndef CK_F_STACK_POP_MPMC
|
|
|
|
|
#define CK_F_STACK_POP_MPMC
|
|
|
|
@ -147,6 +204,30 @@ ck_stack_pop_mpmc(struct ck_stack *target)
|
|
|
|
|
return (original.head);
|
|
|
|
|
}
|
|
|
|
|
#endif /* CK_F_STACK_POP_MPMC */
|
|
|
|
|
|
|
|
|
|
#ifndef CK_F_STACK_TRYPOP_MPMC
|
|
|
|
|
#define CK_F_STACK_TRYPOP_MPMC
|
|
|
|
|
CK_CC_INLINE static bool
|
|
|
|
|
ck_stack_trypop_mpmc(struct ck_stack *target, struct ck_stack_entry **r)
|
|
|
|
|
{
|
|
|
|
|
struct ck_stack original, update;
|
|
|
|
|
|
|
|
|
|
original.generation = ck_pr_load_ptr(&target->generation);
|
|
|
|
|
original.head = ck_pr_load_ptr(&target->head);
|
|
|
|
|
if (original.head == NULL)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
update.generation = original.generation + 1;
|
|
|
|
|
update.head = original.head->next;
|
|
|
|
|
|
|
|
|
|
if (ck_pr_cas_ptr_2_value(target, &original, &update, &original) == true) {
|
|
|
|
|
*r = original.head;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
#endif /* CK_F_STACK_TRYPOP_MPMC */
|
|
|
|
|
#endif /* CK_F_PR_CAS_PTR_2_VALUE */
|
|
|
|
|
|
|
|
|
|
#ifndef CK_F_STACK_BATCH_POP_MPMC
|
|
|
|
|