DPDK 26.11.0-rc2
rte_stack_std.h
1/* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019 Intel Corporation
3 */
4
5#ifndef _RTE_STACK_STD_H_
6#define _RTE_STACK_STD_H_
7
9
22static __rte_always_inline unsigned int
23__rte_stack_std_push(struct rte_stack *s, void * const *obj_table,
24 unsigned int n)
25{
26 struct rte_stack_std *stack = &s->stack_std;
27 unsigned int index;
28 void **stack_objs;
29
30 rte_spinlock_lock(&stack->lock);
31 stack_objs = &stack->objs[stack->len];
32
33 if (unlikely((stack->len + n) > s->capacity)) {
34 /* Insufficient space in the stack. */
35 rte_spinlock_unlock(&stack->lock);
36 return 0;
37 }
38
39 /* Push objects to the stack */
40 for (index = 0; index < n; ++index, obj_table++)
41 stack_objs[index] = *obj_table;
42
43 stack->len += n;
44
45 rte_spinlock_unlock(&stack->lock);
46 return n;
47}
48
61static __rte_always_inline unsigned int
62__rte_stack_std_pop(struct rte_stack *s, void **obj_table, unsigned int n)
63{
64 struct rte_stack_std *stack = &s->stack_std;
65 unsigned int index, len;
66 void **stack_objs;
67
68 rte_spinlock_lock(&stack->lock);
69
70 if (unlikely(n > stack->len)) {
71 /* Insufficient objects in the stack. */
72 rte_spinlock_unlock(&stack->lock);
73 return 0;
74 }
75
76 stack_objs = stack->objs;
77
78 /* Pop objects from the stack */
79 for (index = 0, len = stack->len - 1; index < n;
80 ++index, len--, obj_table++)
81 *obj_table = stack_objs[len];
82
83 stack->len -= n;
84 rte_spinlock_unlock(&stack->lock);
85
86 return n;
87}
88
97static __rte_always_inline unsigned int
98__rte_stack_std_count(struct rte_stack *s)
99{
100 return (unsigned int)s->stack_std.len;
101}
102
109void
110rte_stack_std_init(struct rte_stack *s);
111
120ssize_t
121rte_stack_std_get_memsize(unsigned int count);
122
123#endif /* _RTE_STACK_STD_H_ */
#define unlikely(x)
#define __rte_always_inline
Definition: rte_common.h:534
static void rte_spinlock_unlock(rte_spinlock_t *sl)
static void rte_spinlock_lock(rte_spinlock_t *sl)