CNDP  22.08.0
cne_tailq.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright (c) 2019-2022 Intel Corporation
3  */
4 
5 #ifndef _CNE_TAILQ_H_
6 #define _CNE_TAILQ_H_
7 
17 #include <sys/queue.h>
18 #include <stdio.h>
19 
20 #include <cne_common.h>
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
29  void *data;
30 };
32 TAILQ_HEAD(cne_tailq_entry_head, cne_tailq_entry);
33 
34 #define CNE_MAX_TAILQS 32
35 #define CNE_TAILQ_NAMESIZE 32
36 
44  struct cne_tailq_entry_head tailq_head;
45  char name[CNE_TAILQ_NAMESIZE];
46 };
47 
48 struct cne_tailq_elem {
52  struct cne_tailq_head *head;
53  TAILQ_ENTRY(cne_tailq_elem) next;
54  const char name[CNE_TAILQ_NAMESIZE];
55 };
56 
57 #define CNE_REGISTER_TAILQ(t) \
58  CNE_INIT(tailqinitfn_##t) \
59  { \
60  if (cne_tailq_register(&t) < 0) \
61  cne_panic("Cannot initialize tailq: %s\n", t.name); \
62  }
63 
67 #define CNE_TAILQ_CAST(tailq_entry, struct_name) (struct struct_name *)&(tailq_entry)->tailq_head
68 
85 #define CNE_TAILQ_LOOKUP(name, struct_name) CNE_TAILQ_CAST(cne_tailq_lookup(name), struct_name)
86 
93 CNDP_API int cne_tailqs_init(void);
94 
103 CNDP_API int cne_tailq_register(struct cne_tailq_elem *t);
104 
109 CNDP_API void cne_dump_tailq(void);
110 
124 CNDP_API struct cne_tailq_head *cne_tailq_lookup(const char *name);
125 
140 CNDP_API int cne_eal_tailq_register(struct cne_tailq_elem *t);
141 
145 #ifndef TAILQ_FOREACH_SAFE
146 // clang-format off
147 #define TAILQ_FOREACH_SAFE(var, head, field, tvar) \
148  for ((var) = TAILQ_FIRST((head)); \
149  (var) && ((tvar) = TAILQ_NEXT((var), field), 1); \
150  (var) = (tvar))
151 // clang-format on
152 #endif
153 
154 #ifdef __cplusplus
155 }
156 #endif
157 
158 #endif /* _CNE_TAILQ_H_ */
TAILQ_HEAD(cne_tailq_entry_head, cne_tailq_entry)
CNDP_API int cne_eal_tailq_register(struct cne_tailq_elem *t)
CNDP_API void cne_dump_tailq(void)
CNDP_API int cne_tailqs_init(void)
CNDP_API int cne_tailq_register(struct cne_tailq_elem *t)
CNDP_API struct cne_tailq_head * cne_tailq_lookup(const char *name)
Definition: cne_tailq.h:27
TAILQ_ENTRY(cne_tailq_entry) next
void * data
Definition: cne_tailq.h:29
struct cne_tailq_entry_head tailq_head
Definition: cne_tailq.h:44