tailq: change rte_dummy to rte_tailq_entry
[dpdk.git] / lib / librte_eal / common / include / rte_tailq.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Intel Corporation nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #ifndef _RTE_TAILQ_H_
35 #define _RTE_TAILQ_H_
36
37 /**
38  * @file
39  *  Here defines rte_tailq APIs for only internal use
40  *
41  */
42
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46
47 #include <sys/queue.h>
48 #include <stdio.h>
49
50 /** dummy structure type used by the rte_tailq APIs */
51 struct rte_tailq_entry {
52         TAILQ_ENTRY(rte_tailq_entry) next; /**< Pointer entries for a tailq list */
53         void *data; /**< Pointer to the data referenced by this tailq entry */
54 };
55 /** dummy */
56 TAILQ_HEAD(rte_tailq_entry_head, rte_tailq_entry);
57
58 #define RTE_TAILQ_NAMESIZE 32
59
60 /**
61  * The structure defining a tailq header entry for storing
62  * in the rte_config structure in shared memory. Each tailq
63  * is identified by name.
64  * Any library storing a set of objects e.g. rings, mempools, hash-tables,
65  * is recommended to use an entry here, so as to make it easy for
66  * a multi-process app to find already-created elements in shared memory.
67  */
68 struct rte_tailq_head {
69         struct rte_tailq_entry_head tailq_head; /**< NOTE: must be first element */
70 };
71
72 /**
73  * Utility macro to make reserving a tailqueue for a particular struct easier.
74  *
75  * @param name
76  *   The name to be given to the tailq - used by lookup to find it later
77  *
78  * @param struct_name
79  *   The name of the list type we are using. (Generally this is the same as the
80  *   first parameter passed to TAILQ_HEAD macro)
81  *
82  * @return
83  *   The return value from rte_eal_tailq_reserve, typecast to the appropriate
84  *   structure pointer type.
85  *   NULL on error, since the tailq_head is the first
86  *   element in the rte_tailq_head structure.
87  */
88 #define RTE_TAILQ_RESERVE(name, struct_name) \
89         (struct struct_name *)(&rte_eal_tailq_reserve(name)->tailq_head)
90
91 /**
92  * Utility macro to make reserving a tailqueue for a particular struct easier.
93  *
94  * @param idx
95  *   The tailq idx defined in rte_tail_t to be given to the tail queue.
96  *       - used by lookup to find it later
97  *
98  * @param struct_name
99  *   The name of the list type we are using. (Generally this is the same as the
100  *   first parameter passed to TAILQ_HEAD macro)
101  *
102  * @return
103  *   The return value from rte_eal_tailq_reserve, typecast to the appropriate
104  *   structure pointer type.
105  *   NULL on error, since the tailq_head is the first
106  *   element in the rte_tailq_head structure.
107  */
108 #define RTE_TAILQ_RESERVE_BY_IDX(idx, struct_name) \
109         (struct struct_name *)(&rte_eal_tailq_reserve_by_idx(idx)->tailq_head)
110
111 /**
112  * Utility macro to make looking up a tailqueue for a particular struct easier.
113  *
114  * @param name
115  *   The name of tailq
116  *
117  * @param struct_name
118  *   The name of the list type we are using. (Generally this is the same as the
119  *   first parameter passed to TAILQ_HEAD macro)
120  *
121  * @return
122  *   The return value from rte_eal_tailq_lookup, typecast to the appropriate
123  *   structure pointer type.
124  *   NULL on error, since the tailq_head is the first
125  *   element in the rte_tailq_head structure.
126  */
127 #define RTE_TAILQ_LOOKUP(name, struct_name) \
128         (struct struct_name *)(&rte_eal_tailq_lookup(name)->tailq_head)
129
130 /**
131  * Utility macro to make looking up a tailqueue for a particular struct easier.
132  *
133  * @param idx
134  *   The tailq idx defined in rte_tail_t to be given to the tail queue.
135  *
136  * @param struct_name
137  *   The name of the list type we are using. (Generally this is the same as the
138  *   first parameter passed to TAILQ_HEAD macro)
139  *
140  * @return
141  *   The return value from rte_eal_tailq_lookup, typecast to the appropriate
142  *   structure pointer type.
143  *   NULL on error, since the tailq_head is the first
144  *   element in the rte_tailq_head structure.
145  */
146 #define RTE_TAILQ_LOOKUP_BY_IDX(idx, struct_name) \
147         (struct struct_name *)(&rte_eal_tailq_lookup_by_idx(idx)->tailq_head)
148
149 /**
150  * Reserve a slot in the tailq list for a particular tailq header
151  * Note: this function, along with rte_tailq_lookup, is not multi-thread safe,
152  * and both these functions should only be called from a single thread at a time
153  *
154  * @param name
155  *   The name to be given to the tail queue.
156  * @return
157  *   A pointer to the newly reserved tailq entry
158  */
159 struct rte_tailq_head *rte_eal_tailq_reserve(const char *name);
160
161 /**
162  * Reserve a slot in the tailq list for a particular tailq header
163  * Note: this function, along with rte_tailq_lookup, is not multi-thread safe,
164  * and both these functions should only be called from a single thread at a time
165  *
166  * @param idx
167  *   The tailq idx defined in rte_tail_t to be given to the tail queue.
168  * @return
169  *   A pointer to the newly reserved tailq entry
170  */
171 struct rte_tailq_head *rte_eal_tailq_reserve_by_idx(const unsigned idx);
172
173 /**
174  * Dump tail queues to the console.
175  *
176  * @param f
177  *   A pointer to a file for output
178  */
179 void rte_dump_tailq(FILE *f);
180
181 /**
182  * Lookup for a tail queue.
183  *
184  * Get a pointer to a tail queue header of an already reserved tail
185  * queue identified by the name given as an argument.
186  * Note: this function, along with rte_tailq_reserve, is not multi-thread safe,
187  * and both these functions should only be called from a single thread at a time
188  *
189  * @param name
190  *   The name of the queue.
191  * @return
192  *   A pointer to the tail queue head structure.
193  */
194 struct rte_tailq_head *rte_eal_tailq_lookup(const char *name);
195
196 /**
197  * Lookup for a tail queue.
198  *
199  * Get a pointer to a tail queue header of an already reserved tail
200  * queue identified by the name given as an argument.
201  * Note: this function, along with rte_tailq_reserve, is not multi-thread safe,
202  * and both these functions should only be called from a single thread at a time
203  *
204  * @param idx
205  *   The tailq idx defined in rte_tail_t to be given to the tail queue.
206  * @return
207  *   A pointer to the tail queue head structure.
208  */
209 struct rte_tailq_head *rte_eal_tailq_lookup_by_idx(const unsigned idx);
210
211 #ifdef __cplusplus
212 }
213 #endif
214
215 #endif /* _RTE_TAILQ_H_ */