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 8 /** 9 * @file 10 * Here defines rte_tailq APIs for only internal use 11 * 12 */ 13 14 #ifdef __cplusplus 15 extern "C" { 16 #endif 17 18 #include <stdio.h> 19 #include <rte_debug.h> 20 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 */ 25 }; 26 /** dummy */ 27 RTE_TAILQ_HEAD(rte_tailq_entry_head, rte_tailq_entry); 28 29 #define RTE_TAILQ_NAMESIZE 32 30 31 /** 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. 38 */ 39 struct rte_tailq_head { 40 struct rte_tailq_entry_head tailq_head; /**< NOTE: must be first element */ 41 char name[RTE_TAILQ_NAMESIZE]; 42 }; 43 44 struct rte_tailq_elem { 45 /** 46 * Reference to head in shared mem, updated at init time by 47 * rte_eal_tailqs_init() 48 */ 49 struct rte_tailq_head *head; 50 RTE_TAILQ_ENTRY(rte_tailq_elem) next; 51 const char name[RTE_TAILQ_NAMESIZE]; 52 }; 53 54 /** 55 * Return the first tailq entry cast to the right struct. 56 */ 57 #define RTE_TAILQ_CAST(tailq_entry, struct_name) \ 58 (struct struct_name *)&(tailq_entry)->tailq_head 59 60 /** 61 * Utility macro to make looking up a tailqueue for a particular struct easier. 62 * 63 * @param name 64 * The name of tailq 65 * 66 * @param struct_name 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) 69 * 70 * @return 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. 75 */ 76 #define RTE_TAILQ_LOOKUP(name, struct_name) \ 77 RTE_TAILQ_CAST(rte_eal_tailq_lookup(name), struct_name) 78 79 /** 80 * Dump tail queues to a file. 81 * 82 * @param f 83 * A pointer to a file for output 84 */ 85 void rte_dump_tailq(FILE *f); 86 87 /** 88 * Lookup for a tail queue. 89 * 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 94 * 95 * @param name 96 * The name of the queue. 97 * @return 98 * A pointer to the tail queue head structure. 99 */ 100 struct rte_tailq_head *rte_eal_tailq_lookup(const char *name); 101 102 /** 103 * Register a tail queue. 104 * 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(). 111 * 112 * @param t 113 * The tailq element which contains the name of the tailq you want to 114 * create (/retrieve when in secondary process). 115 * @return 116 * 0 on success or -1 in case of an error. 117 */ 118 int rte_eal_tailq_register(struct rte_tailq_elem *t); 119 120 #define EAL_REGISTER_TAILQ(t) \ 121 RTE_INIT(tailqinitfn_ ##t) \ 122 { \ 123 if (rte_eal_tailq_register(&t) < 0) \ 124 rte_panic("Cannot initialize tailq: %s\n", t.name); \ 125 } 126 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); \ 131 (var) = (tvar)) 132 133 #ifdef __cplusplus 134 } 135 #endif 136 137 #endif /* _RTE_TAILQ_H_ */ 138