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*).
22 static __rte_always_inline unsigned int
23 __rte_stack_std_push(struct rte_stack *s, void * const *obj_table,
26 struct rte_stack_std *stack = &s->stack_std;
30 rte_spinlock_lock(&stack->lock);
31 cache_objs = &stack->objs[stack->len];
33 /* Is there sufficient space in the stack? */
34 if ((stack->len + n) > s->capacity) {
35 rte_spinlock_unlock(&stack->lock);
39 /* Add elements back into the cache */
40 for (index = 0; index < n; ++index, obj_table++)
41 cache_objs[index] = *obj_table;
45 rte_spinlock_unlock(&stack->lock);
50 * @internal Pop several objects from the stack (MT-safe).
53 * A pointer to the stack structure.
55 * A pointer to a table of void * pointers (objects).
57 * The number of objects to pull from the stack.
59 * Actual number of objects popped (either 0 or *n*).
61 static __rte_always_inline unsigned int
62 __rte_stack_std_pop(struct rte_stack *s, void **obj_table, unsigned int n)
64 struct rte_stack_std *stack = &s->stack_std;
65 unsigned int index, len;
68 rte_spinlock_lock(&stack->lock);
70 if (unlikely(n > stack->len)) {
71 rte_spinlock_unlock(&stack->lock);
75 cache_objs = stack->objs;
77 for (index = 0, len = stack->len - 1; index < n;
78 ++index, len--, obj_table++)
79 *obj_table = cache_objs[len];
82 rte_spinlock_unlock(&stack->lock);
88 * @internal Return the number of used entries in a stack.
91 * A pointer to the stack structure.
93 * The number of used entries in the stack.
95 static __rte_always_inline unsigned int
96 __rte_stack_std_count(struct rte_stack *s)
98 return (unsigned int)s->stack_std.len;
102 * @internal Initialize a standard stack.
105 * A pointer to the stack structure.
108 rte_stack_std_init(struct rte_stack *s);
111 * @internal Return the memory required for a standard stack.
114 * The size of the stack.
116 * The bytes to allocate for a standard stack.
119 rte_stack_std_get_memsize(unsigned int count);
121 #endif /* _RTE_STACK_STD_H_ */