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 #include <stdio.h> 14 #include <rte_debug.h> 15 16 #ifdef __cplusplus 17 extern "C" { 18 #endif 19 20 /** dummy structure type used by the rte_tailq APIs */ 21 struct rte_tailq_entry { 22 RTE_TAILQ_ENTRY(rte_tailq_entry) next; /**< Pointer entries for a tailq list */ 23 void *data; /**< Pointer to the data referenced by this tailq entry */ 24 }; 25 /** dummy */ 26 RTE_TAILQ_HEAD(rte_tailq_entry_head, rte_tailq_entry); 27 28 #define RTE_TAILQ_NAMESIZE 32 29 30 /** 31 * The structure defining a tailq header entry for storing 32 * in the rte_config structure in shared memory. Each tailq 33 * is identified by name. 34 * Any library storing a set of objects e.g. rings, mempools, hash-tables, 35 * is recommended to use an entry here, so as to make it easy for 36 * a multi-process app to find already-created elements in shared memory. 37 */ 38 struct rte_tailq_head { 39 struct rte_tailq_entry_head tailq_head; /**< NOTE: must be first element */ 40 char name[RTE_TAILQ_NAMESIZE]; 41 }; 42 43 struct rte_tailq_elem { 44 /** 45 * Reference to head in shared mem, updated at init time by 46 * rte_eal_tailqs_init() 47 */ 48 struct rte_tailq_head *head; 49 RTE_TAILQ_ENTRY(rte_tailq_elem) next; 50 const char name[RTE_TAILQ_NAMESIZE]; 51 }; 52 53 /** 54 * Return the first tailq entry cast to the right struct. 55 */ 56 #define RTE_TAILQ_CAST(tailq_entry, struct_name) \ 57 (struct struct_name *)&(tailq_entry)->tailq_head 58 59 /** 60 * Utility macro to make looking up a tailqueue for a particular struct easier. 61 * 62 * @param name 63 * The name of tailq 64 * 65 * @param struct_name 66 * The name of the list type we are using. (Generally this is the same as the 67 * first parameter passed to TAILQ_HEAD macro) 68 * 69 * @return 70 * The return value from rte_eal_tailq_lookup, typecast to the appropriate 71 * structure pointer type. 72 * NULL on error, since the tailq_head is the first 73 * element in the rte_tailq_head structure. 74 */ 75 #define RTE_TAILQ_LOOKUP(name, struct_name) \ 76 RTE_TAILQ_CAST(rte_eal_tailq_lookup(name), struct_name) 77 78 /** 79 * Dump tail queues to a file. 80 * 81 * @param f 82 * A pointer to a file for output 83 */ 84 void rte_dump_tailq(FILE *f); 85 86 /** 87 * Lookup for a tail queue. 88 * 89 * Get a pointer to a tail queue header of a tail 90 * queue identified by the name given as an argument. 91 * Note: this function is not multi-thread safe, and should only be called from 92 * a single thread at a time 93 * 94 * @param name 95 * The name of the queue. 96 * @return 97 * A pointer to the tail queue head structure. 98 */ 99 struct rte_tailq_head *rte_eal_tailq_lookup(const char *name); 100 101 /** 102 * Register a tail queue. 103 * 104 * Register a tail queue from shared memory. 105 * This function is mainly used by EAL_REGISTER_TAILQ macro which is used to 106 * register tailq from the different dpdk libraries. Since this macro is a 107 * constructor, the function has no access to dpdk shared memory, so the 108 * registered tailq can not be used before call to rte_eal_init() which calls 109 * rte_eal_tailqs_init(). 110 * 111 * @param t 112 * The tailq element which contains the name of the tailq you want to 113 * create (/retrieve when in secondary process). 114 * @return 115 * 0 on success or -1 in case of an error. 116 */ 117 int rte_eal_tailq_register(struct rte_tailq_elem *t); 118 119 #define EAL_REGISTER_TAILQ(t) \ 120 RTE_INIT(tailqinitfn_ ##t) \ 121 { \ 122 if (rte_eal_tailq_register(&t) < 0) \ 123 rte_panic("Cannot initialize tailq: %s\n", t.name); \ 124 } 125 126 /* This macro permits both remove and free var within the loop safely.*/ 127 #define RTE_TAILQ_FOREACH_SAFE(var, head, field, tvar) \ 128 for ((var) = RTE_TAILQ_FIRST((head)); \ 129 (var) && ((tvar) = RTE_TAILQ_NEXT((var), field), 1); \ 130 (var) = (tvar)) 131 132 #ifdef __cplusplus 133 } 134 #endif 135 136 #endif /* _RTE_TAILQ_H_ */ 137