1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019 Intel Corporation
5 #ifndef _RTE_STACK_STD_H_
6 #define _RTE_STACK_STD_H_
8 #include <rte_branch_prediction.h>
11 * @internal Push several objects on the stack (MT-safe).
14 * A pointer to the stack structure.
16 * A pointer to a table of void * pointers (objects).
18 * The number of objects to push on the stack from the obj_table.
20 * Actual number of objects pushed (either 0 or *n*).
23 static __rte_always_inline unsigned int
24 __rte_stack_std_push(struct rte_stack *s, void * const *obj_table,
27 struct rte_stack_std *stack = &s->stack_std;
31 rte_spinlock_lock(&stack->lock);
32 cache_objs = &stack->objs[stack->len];
34 /* Is there sufficient space in the stack? */
35 if ((stack->len + n) > s->capacity) {
36 rte_spinlock_unlock(&stack->lock);
40 /* Add elements back into the cache */
41 for (index = 0; index < n; ++index, obj_table++)
42 cache_objs[index] = *obj_table;
46 rte_spinlock_unlock(&stack->lock);
51 * @internal Pop several objects from the stack (MT-safe).
54 * A pointer to the stack structure.
56 * A pointer to a table of void * pointers (objects).
58 * The number of objects to pull from the stack.
60 * Actual number of objects popped (either 0 or *n*).
63 static __rte_always_inline unsigned int
64 __rte_stack_std_pop(struct rte_stack *s, void **obj_table, unsigned int n)
66 struct rte_stack_std *stack = &s->stack_std;
67 unsigned int index, len;
70 rte_spinlock_lock(&stack->lock);
72 if (unlikely(n > stack->len)) {
73 rte_spinlock_unlock(&stack->lock);
77 cache_objs = stack->objs;
79 for (index = 0, len = stack->len - 1; index < n;
80 ++index, len--, obj_table++)
81 *obj_table = cache_objs[len];
84 rte_spinlock_unlock(&stack->lock);
90 * @internal Return the number of used entries in a stack.
93 * A pointer to the stack structure.
95 * The number of used entries in the stack.
98 static __rte_always_inline unsigned int
99 __rte_stack_std_count(struct rte_stack *s)
101 return (unsigned int)s->stack_std.len;
105 * @internal Initialize a standard stack.
108 * A pointer to the stack structure.
111 rte_stack_std_init(struct rte_stack *s);
114 * @internal Return the memory required for a standard stack.
117 * The size of the stack.
119 * The bytes to allocate for a standard stack.
122 rte_stack_std_get_memsize(unsigned int count);
124 #endif /* _RTE_STACK_STD_H_ */