DPDK  20.05.0-rc0
rte_stack_lf.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2019 Intel Corporation
3  */
4 
5 #ifndef _RTE_STACK_LF_H_
6 #define _RTE_STACK_LF_H_
7 
8 #if !(defined(RTE_ARCH_X86_64) || defined(RTE_ARCH_ARM64))
9 #include "rte_stack_lf_stubs.h"
10 #else
11 #ifdef RTE_USE_C11_MEM_MODEL
12 #include "rte_stack_lf_c11.h"
13 #else
14 #include "rte_stack_lf_generic.h"
15 #endif
16 #endif
17 
30 __rte_experimental
31 static __rte_always_inline unsigned int
32 __rte_stack_lf_push(struct rte_stack *s,
33  void * const *obj_table,
34  unsigned int n)
35 {
36  struct rte_stack_lf_elem *tmp, *first, *last = NULL;
37  unsigned int i;
38 
39  if (unlikely(n == 0))
40  return 0;
41 
42  /* Pop n free elements */
43  first = __rte_stack_lf_pop_elems(&s->stack_lf.free, n, NULL, &last);
44  if (unlikely(first == NULL))
45  return 0;
46 
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];
50 
51  /* Push them to the used list */
52  __rte_stack_lf_push_elems(&s->stack_lf.used, first, last, n);
53 
54  return n;
55 }
56 
69 __rte_experimental
70 static __rte_always_inline unsigned int
71 __rte_stack_lf_pop(struct rte_stack *s, void **obj_table, unsigned int n)
72 {
73  struct rte_stack_lf_elem *first, *last = NULL;
74 
75  if (unlikely(n == 0))
76  return 0;
77 
78  /* Pop n used elements */
79  first = __rte_stack_lf_pop_elems(&s->stack_lf.used,
80  n, obj_table, &last);
81  if (unlikely(first == NULL))
82  return 0;
83 
84  /* Push the list elements to the free list */
85  __rte_stack_lf_push_elems(&s->stack_lf.free, first, last, n);
86 
87  return n;
88 }
89 
98 void
99 rte_stack_lf_init(struct rte_stack *s, unsigned int count);
100 
109 ssize_t
110 rte_stack_lf_get_memsize(unsigned int count);
111 
112 #endif /* _RTE_STACK_LF_H_ */
#define __rte_always_inline
Definition: rte_common.h:183
#define unlikely(x)