1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
10 * Here defines rte_tailq APIs for only internal use
18 #include <sys/queue.h>
20 #include <rte_debug.h>
22 /** dummy structure type used by the rte_tailq APIs */
23 struct rte_tailq_entry {
24 TAILQ_ENTRY(rte_tailq_entry) next; /**< Pointer entries for a tailq list */
25 void *data; /**< Pointer to the data referenced by this tailq entry */
28 TAILQ_HEAD(rte_tailq_entry_head, rte_tailq_entry);
30 #define RTE_TAILQ_NAMESIZE 32
33 * The structure defining a tailq header entry for storing
34 * in the rte_config structure in shared memory. Each tailq
35 * is identified by name.
36 * Any library storing a set of objects e.g. rings, mempools, hash-tables,
37 * is recommended to use an entry here, so as to make it easy for
38 * a multi-process app to find already-created elements in shared memory.
40 struct rte_tailq_head {
41 struct rte_tailq_entry_head tailq_head; /**< NOTE: must be first element */
42 char name[RTE_TAILQ_NAMESIZE];
45 struct rte_tailq_elem {
47 * Reference to head in shared mem, updated at init time by
48 * rte_eal_tailqs_init()
50 struct rte_tailq_head *head;
51 TAILQ_ENTRY(rte_tailq_elem) next;
52 const char name[RTE_TAILQ_NAMESIZE];
56 * Return the first tailq entry cast to the right struct.
58 #define RTE_TAILQ_CAST(tailq_entry, struct_name) \
59 (struct struct_name *)&(tailq_entry)->tailq_head
62 * Utility macro to make looking up a tailqueue for a particular struct easier.
68 * The name of the list type we are using. (Generally this is the same as the
69 * first parameter passed to TAILQ_HEAD macro)
72 * The return value from rte_eal_tailq_lookup, typecast to the appropriate
73 * structure pointer type.
74 * NULL on error, since the tailq_head is the first
75 * element in the rte_tailq_head structure.
77 #define RTE_TAILQ_LOOKUP(name, struct_name) \
78 RTE_TAILQ_CAST(rte_eal_tailq_lookup(name), struct_name)
81 * Dump tail queues to a file.
84 * A pointer to a file for output
86 void rte_dump_tailq(FILE *f);
89 * Lookup for a tail queue.
91 * Get a pointer to a tail queue header of a tail
92 * queue identified by the name given as an argument.
93 * Note: this function is not multi-thread safe, and should only be called from
94 * a single thread at a time
97 * The name of the queue.
99 * A pointer to the tail queue head structure.
101 struct rte_tailq_head *rte_eal_tailq_lookup(const char *name);
104 * Register a tail queue.
106 * Register a tail queue from shared memory.
107 * This function is mainly used by EAL_REGISTER_TAILQ macro which is used to
108 * register tailq from the different dpdk libraries. Since this macro is a
109 * constructor, the function has no access to dpdk shared memory, so the
110 * registered tailq can not be used before call to rte_eal_init() which calls
111 * rte_eal_tailqs_init().
114 * The tailq element which contains the name of the tailq you want to
115 * create (/retrieve when in secondary process).
117 * 0 on success or -1 in case of an error.
119 int rte_eal_tailq_register(struct rte_tailq_elem *t);
121 #define EAL_REGISTER_TAILQ(t) \
122 RTE_INIT(tailqinitfn_ ##t) \
124 if (rte_eal_tailq_register(&t) < 0) \
125 rte_panic("Cannot initialize tailq: %s\n", t.name); \
128 /* This macro permits both remove and free var within the loop safely.*/
129 #ifndef TAILQ_FOREACH_SAFE
130 #define TAILQ_FOREACH_SAFE(var, head, field, tvar) \
131 for ((var) = TAILQ_FIRST((head)); \
132 (var) && ((tvar) = TAILQ_NEXT((var), field), 1); \
140 #endif /* _RTE_TAILQ_H_ */