1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019 Intel Corporation
5 #ifndef _RTE_STACK_LF_H_
6 #define _RTE_STACK_LF_H_
8 #if !(defined(RTE_ARCH_X86_64) || defined(RTE_ARCH_ARM64))
9 #include "rte_stack_lf_stubs.h"
11 #ifdef RTE_USE_C11_MEM_MODEL
12 #include "rte_stack_lf_c11.h"
14 #include "rte_stack_lf_generic.h"
19 * @internal Push several objects on the lock-free stack (MT-safe).
22 * A pointer to the stack structure.
24 * A pointer to a table of void * pointers (objects).
26 * The number of objects to push on the stack from the obj_table.
28 * Actual number of objects enqueued.
31 static __rte_always_inline unsigned int
32 __rte_stack_lf_push(struct rte_stack *s,
33 void * const *obj_table,
36 struct rte_stack_lf_elem *tmp, *first, *last = NULL;
42 /* Pop n free elements */
43 first = __rte_stack_lf_pop_elems(&s->stack_lf.free, n, NULL, &last);
44 if (unlikely(first == NULL))
47 /* Construct the list elements */
48 for (tmp = first, i = 0; i < n; i++, tmp = tmp->next)
49 tmp->data = obj_table[n - i - 1];
51 /* Push them to the used list */
52 __rte_stack_lf_push_elems(&s->stack_lf.used, first, last, n);
58 * @internal Pop several objects from the lock-free stack (MT-safe).
61 * A pointer to the stack structure.
63 * A pointer to a table of void * pointers (objects).
65 * The number of objects to pull from the stack.
67 * - Actual number of objects popped.
70 static __rte_always_inline unsigned int
71 __rte_stack_lf_pop(struct rte_stack *s, void **obj_table, unsigned int n)
73 struct rte_stack_lf_elem *first, *last = NULL;
78 /* Pop n used elements */
79 first = __rte_stack_lf_pop_elems(&s->stack_lf.used,
81 if (unlikely(first == NULL))
84 /* Push the list elements to the free list */
85 __rte_stack_lf_push_elems(&s->stack_lf.free, first, last, n);
91 * @internal Initialize a lock-free stack.
94 * A pointer to the stack structure.
96 * The size of the stack.
99 rte_stack_lf_init(struct rte_stack *s, unsigned int count);
102 * @internal Return the memory required for a lock-free stack.
105 * The size of the stack.
107 * The bytes to allocate for a lock-free stack.
110 rte_stack_lf_get_memsize(unsigned int count);
112 #endif /* _RTE_STACK_LF_H_ */