devtools: pass custom options to checkpatch
[dpdk.git] / lib / librte_stack / 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 #ifdef RTE_USE_C11_MEM_MODEL
9 #include "rte_stack_lf_c11.h"
10 #else
11 #include "rte_stack_lf_generic.h"
12 #endif
13
14 /**
15  * @internal Push several objects on the lock-free stack (MT-safe).
16  *
17  * @param s
18  *   A pointer to the stack structure.
19  * @param obj_table
20  *   A pointer to a table of void * pointers (objects).
21  * @param n
22  *   The number of objects to push on the stack from the obj_table.
23  * @return
24  *   Actual number of objects enqueued.
25  */
26 __rte_experimental
27 static __rte_always_inline unsigned int
28 __rte_stack_lf_push(struct rte_stack *s,
29                     void * const *obj_table,
30                     unsigned int n)
31 {
32         struct rte_stack_lf_elem *tmp, *first, *last = NULL;
33         unsigned int i;
34
35         if (unlikely(n == 0))
36                 return 0;
37
38         /* Pop n free elements */
39         first = __rte_stack_lf_pop_elems(&s->stack_lf.free, n, NULL, &last);
40         if (unlikely(first == NULL))
41                 return 0;
42
43         /* Construct the list elements */
44         for (tmp = first, i = 0; i < n; i++, tmp = tmp->next)
45                 tmp->data = obj_table[n - i - 1];
46
47         /* Push them to the used list */
48         __rte_stack_lf_push_elems(&s->stack_lf.used, first, last, n);
49
50         return n;
51 }
52
53 /**
54  * @internal Pop several objects from the lock-free stack (MT-safe).
55  *
56  * @param s
57  *   A pointer to the stack structure.
58  * @param obj_table
59  *   A pointer to a table of void * pointers (objects).
60  * @param n
61  *   The number of objects to pull from the stack.
62  * @return
63  *   - Actual number of objects popped.
64  */
65 __rte_experimental
66 static __rte_always_inline unsigned int
67 __rte_stack_lf_pop(struct rte_stack *s, void **obj_table, unsigned int n)
68 {
69         struct rte_stack_lf_elem *first, *last = NULL;
70
71         if (unlikely(n == 0))
72                 return 0;
73
74         /* Pop n used elements */
75         first = __rte_stack_lf_pop_elems(&s->stack_lf.used,
76                                          n, obj_table, &last);
77         if (unlikely(first == NULL))
78                 return 0;
79
80         /* Push the list elements to the free list */
81         __rte_stack_lf_push_elems(&s->stack_lf.free, first, last, n);
82
83         return n;
84 }
85
86 /**
87  * @internal Initialize a lock-free stack.
88  *
89  * @param s
90  *   A pointer to the stack structure.
91  * @param count
92  *   The size of the stack.
93  */
94 void
95 rte_stack_lf_init(struct rte_stack *s, unsigned int count);
96
97 /**
98  * @internal Return the memory required for a lock-free stack.
99  *
100  * @param count
101  *   The size of the stack.
102  * @return
103  *   The bytes to allocate for a lock-free stack.
104  */
105 ssize_t
106 rte_stack_lf_get_memsize(unsigned int count);
107
108 #endif /* _RTE_STACK_LF_H_ */