DPDK  18.05.1
rte_tailq.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2014 Intel Corporation
3  */
4 
5 #ifndef _RTE_TAILQ_H_
6 #define _RTE_TAILQ_H_
7 
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17 
18 #include <sys/queue.h>
19 #include <stdio.h>
20 #include <rte_debug.h>
21 
25  void *data;
26 };
28 TAILQ_HEAD(rte_tailq_entry_head, rte_tailq_entry);
29 
30 #define RTE_TAILQ_NAMESIZE 32
31 
41  struct rte_tailq_entry_head tailq_head;
42  char name[RTE_TAILQ_NAMESIZE];
43 };
44 
45 struct rte_tailq_elem {
50  struct rte_tailq_head *head;
51  TAILQ_ENTRY(rte_tailq_elem) next;
52  const char name[RTE_TAILQ_NAMESIZE];
53 };
54 
58 #define RTE_TAILQ_CAST(tailq_entry, struct_name) \
59  (struct struct_name *)&(tailq_entry)->tailq_head
60 
77 #define RTE_TAILQ_LOOKUP(name, struct_name) \
78  RTE_TAILQ_CAST(rte_eal_tailq_lookup(name), struct_name)
79 
86 void rte_dump_tailq(FILE *f);
87 
101 struct rte_tailq_head *rte_eal_tailq_lookup(const char *name);
102 
119 int rte_eal_tailq_register(struct rte_tailq_elem *t);
120 
121 #define EAL_REGISTER_TAILQ(t) \
122 RTE_INIT(tailqinitfn_ ##t); \
123 static void tailqinitfn_ ##t(void) \
124 { \
125  if (rte_eal_tailq_register(&t) < 0) \
126  rte_panic("Cannot initialize tailq: %s\n", t.name); \
127 }
128 
129 /* This macro permits both remove and free var within the loop safely.*/
130 #ifndef TAILQ_FOREACH_SAFE
131 #define TAILQ_FOREACH_SAFE(var, head, field, tvar) \
132  for ((var) = TAILQ_FIRST((head)); \
133  (var) && ((tvar) = TAILQ_NEXT((var), field), 1); \
134  (var) = (tvar))
135 #endif
136 
137 #ifdef __cplusplus
138 }
139 #endif
140 
141 #endif /* _RTE_TAILQ_H_ */