1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
10 * Here defines rte_tailq APIs for only internal use
19 #include <rte_debug.h>
21 /** dummy structure type used by the rte_tailq APIs */
22 struct rte_tailq_entry {
23 RTE_TAILQ_ENTRY(rte_tailq_entry) next; /**< Pointer entries for a tailq list */
24 void *data; /**< Pointer to the data referenced by this tailq entry */
27 RTE_TAILQ_HEAD(rte_tailq_entry_head, rte_tailq_entry);
29 #define RTE_TAILQ_NAMESIZE 32
32 * The structure defining a tailq header entry for storing
33 * in the rte_config structure in shared memory. Each tailq
34 * is identified by name.
35 * Any library storing a set of objects e.g. rings, mempools, hash-tables,
36 * is recommended to use an entry here, so as to make it easy for
37 * a multi-process app to find already-created elements in shared memory.
39 struct rte_tailq_head {
40 struct rte_tailq_entry_head tailq_head; /**< NOTE: must be first element */
41 char name[RTE_TAILQ_NAMESIZE];
44 struct rte_tailq_elem {
46 * Reference to head in shared mem, updated at init time by
47 * rte_eal_tailqs_init()
49 struct rte_tailq_head *head;
50 RTE_TAILQ_ENTRY(rte_tailq_elem) next;
51 const char name[RTE_TAILQ_NAMESIZE];
55 * Return the first tailq entry cast to the right struct.
57 #define RTE_TAILQ_CAST(tailq_entry, struct_name) \
58 (struct struct_name *)&(tailq_entry)->tailq_head
61 * Utility macro to make looking up a tailqueue for a particular struct easier.
67 * The name of the list type we are using. (Generally this is the same as the
68 * first parameter passed to TAILQ_HEAD macro)
71 * The return value from rte_eal_tailq_lookup, typecast to the appropriate
72 * structure pointer type.
73 * NULL on error, since the tailq_head is the first
74 * element in the rte_tailq_head structure.
76 #define RTE_TAILQ_LOOKUP(name, struct_name) \
77 RTE_TAILQ_CAST(rte_eal_tailq_lookup(name), struct_name)
80 * Dump tail queues to a file.
83 * A pointer to a file for output
85 void rte_dump_tailq(FILE *f);
88 * Lookup for a tail queue.
90 * Get a pointer to a tail queue header of a tail
91 * queue identified by the name given as an argument.
92 * Note: this function is not multi-thread safe, and should only be called from
93 * a single thread at a time
96 * The name of the queue.
98 * A pointer to the tail queue head structure.
100 struct rte_tailq_head *rte_eal_tailq_lookup(const char *name);
103 * Register a tail queue.
105 * Register a tail queue from shared memory.
106 * This function is mainly used by EAL_REGISTER_TAILQ macro which is used to
107 * register tailq from the different dpdk libraries. Since this macro is a
108 * constructor, the function has no access to dpdk shared memory, so the
109 * registered tailq can not be used before call to rte_eal_init() which calls
110 * rte_eal_tailqs_init().
113 * The tailq element which contains the name of the tailq you want to
114 * create (/retrieve when in secondary process).
116 * 0 on success or -1 in case of an error.
118 int rte_eal_tailq_register(struct rte_tailq_elem *t);
120 #define EAL_REGISTER_TAILQ(t) \
121 RTE_INIT(tailqinitfn_ ##t) \
123 if (rte_eal_tailq_register(&t) < 0) \
124 rte_panic("Cannot initialize tailq: %s\n", t.name); \
127 /* This macro permits both remove and free var within the loop safely.*/
128 #define RTE_TAILQ_FOREACH_SAFE(var, head, field, tvar) \
129 for ((var) = RTE_TAILQ_FIRST((head)); \
130 (var) && ((tvar) = RTE_TAILQ_NEXT((var), field), 1); \
137 #endif /* _RTE_TAILQ_H_ */