21 #ifndef SRC_VPPINFRA_CLIB_LLIST_H_ 22 #define SRC_VPPINFRA_CLIB_LLIST_H_ 35 #define CLIB_LLIST_INVALID_INDEX ((u32)~0) 40 #define _ll_var(v) _llist_##v 44 #define _lnext(E,name) ((E)->name).next 45 #define _lprev(E,name) ((E)->name).prev 53 #define clib_llist_entry_index(LP,E) ((E) - (LP)) 60 #define clib_llist_get(LP, E) pool_get (LP, E) 67 #define clib_llist_put(LP, E) pool_put (LP, E) 73 #define clib_llist_free(LP) pool_free (LP) 81 #define clib_llist_elt(LP, EI) pool_elt_at_index (LP, EI) 91 #define clib_llist_elts(LP) pool_elts (LP) 99 #define clib_llist_prev_index(E,name) _lprev(E,name) 107 #define clib_llist_next_index(E,name) _lnext(E,name) 116 #define clib_llist_next(LP,name,E) pool_elt_at_index((LP),_lnext((E),name)) 125 #define clib_llist_prev(LP,name,E) pool_elt_at_index((LP),_lprev((E),name)) 133 #define clib_llist_anchor_init(LP,name,E) \ 135 _lprev ((E),name) = clib_llist_entry_index ((LP), (E)); \ 136 _lnext ((E),name) = _lprev ((E),name); \ 144 #define clib_llist_make_head(LP,name) \ 146 typeof (LP) _ll_var (head); \ 147 pool_get_zero ((LP), _ll_var (head)); \ 148 clib_llist_anchor_init ((LP),name,_ll_var (head)); \ 149 clib_llist_entry_index ((LP), _ll_var (head)); \ 159 #define clib_llist_is_empty(LP,name,H) \ 160 (clib_llist_entry_index (LP,H) == (H)->name.next) 167 #define clib_llist_elt_is_linked(E,name) \ 168 ((E)->name.next != CLIB_LLIST_INVALID_INDEX \ 169 && (E)->name.prev != CLIB_LLIST_INVALID_INDEX) 181 #define _llist_insert(LP,name,E,P,N) \ 183 _lprev (E,name) = _lprev(N,name); \ 184 _lnext (E,name) = _lnext(P,name); \ 185 _lprev ((N),name) = clib_llist_entry_index ((LP),(E)); \ 186 _lnext ((P),name) = clib_llist_entry_index ((LP),(E)); \ 196 #define clib_llist_insert(LP,name,E,P) \ 198 typeof (LP) _ll_var (N) = clib_llist_next (LP,name,P); \ 199 _llist_insert ((LP),name,(E),(P), _ll_var (N)); \ 210 #define clib_llist_add(LP,name,E,H) clib_llist_insert ((LP),name,(E),(H)) 219 #define clib_llist_add_tail(LP,name,E,H) \ 221 typeof (LP) _ll_var (P) = clib_llist_prev ((LP),name,(H)); \ 222 _llist_insert ((LP),name,(E),_ll_var (P),(H)); \ 231 #define clib_llist_remove(LP,name,E) \ 233 ASSERT ((E) != clib_llist_next (LP,name,E));\ 234 ASSERT (_lnext (E,name) != CLIB_LLIST_INVALID_INDEX); \ 235 ASSERT (_lprev (E,name) != CLIB_LLIST_INVALID_INDEX); \ 236 typeof (LP) _ll_var (P) = clib_llist_prev ((LP),name,E); \ 237 typeof (LP) _ll_var (N) = clib_llist_next ((LP),name,E); \ 238 _lnext (_ll_var (P),name) = _lnext (E,name); \ 239 _lprev (_ll_var (N),name) = _lprev (E,name); \ 240 _lnext (E,name) = _lprev (E,name) = CLIB_LLIST_INVALID_INDEX; \ 253 #define clib_llist_pop_first(LP,name,E,H) \ 255 E = clib_llist_next (LP,name,H); \ 256 clib_llist_remove (LP,name,E); \ 269 #define clib_llist_splice(LP,name,P,H) \ 271 typeof (LP) _ll_var (fe) = clib_llist_next (LP,name,H); \ 272 if (_ll_var (fe) != (H)) \ 274 typeof (LP) _ll_var (le) = clib_llist_prev (LP,name,H); \ 275 typeof (LP) _ll_var (ne) = clib_llist_next (LP,name,P); \ 276 _lprev (_ll_var (fe),name) = clib_llist_entry_index(LP,P); \ 277 _lnext (_ll_var (le),name) = clib_llist_entry_index(LP,_ll_var (ne));\ 278 _lnext (P,name) = clib_llist_entry_index (LP,_ll_var (fe)); \ 279 _lprev (_ll_var (ne),name) = clib_llist_entry_index(LP,_ll_var (le));\ 280 _lnext (H,name) = clib_llist_entry_index(LP,H); \ 281 _lprev (H,name) = _lnext (H,name); \ 293 #define clib_llist_foreach(LP,name,H,E,body) \ 295 typeof (LP) _ll_var (n); \ 296 (E) = clib_llist_next (LP,name,H); \ 299 _ll_var (n) = clib_llist_next (LP,name,E); \ 300 do { body; } while (0); \ 313 #define clib_llist_foreach_safe(LP,name,H,E,body) \ 315 clib_llist_index_t _ll_var (HI) = clib_llist_entry_index (LP, H); \ 316 clib_llist_index_t _ll_var (EI), _ll_var (NI); \ 317 _ll_var (EI) = _lnext ((H),name); \ 318 while (_ll_var (EI) != _ll_var (HI)) \ 320 (E) = pool_elt_at_index (LP, _ll_var (EI)); \ 321 _ll_var (NI) = _lnext ((E),name); \ 322 do { body; } while (0); \ 323 _ll_var (EI) = _ll_var (NI); \ 335 #define clib_llist_foreach_reverse(LP,name,H,E,body) \ 337 typeof (LP) _ll_var (p); \ 338 (E) = clib_llist_prev (LP,name,H); \ 341 _ll_var (p) = clib_llist_prev (LP,name,E); \ 342 do { body; } while (0); \
Fixed length block allocator.
struct clib_llist_anchor clib_llist_anchor_t