From 614ac5da53bca8c8fad5733e6749ec8753c52f28 Mon Sep 17 00:00:00 2001 From: Dave Barach Date: Mon, 6 Feb 2017 09:28:03 -0500 Subject: Add pool_get[_aligned]_will_expand(...) Change-Id: Iefffcf7843dc11803d69a875a72704a2543911a1 Signed-off-by: Dave Barach --- src/vppinfra/pool.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/vppinfra/pool.h') diff --git a/src/vppinfra/pool.h b/src/vppinfra/pool.h index e1c89e0a..586d13e7 100644 --- a/src/vppinfra/pool.h +++ b/src/vppinfra/pool.h @@ -199,6 +199,33 @@ do { \ /** Allocate an object E from a pool P (unspecified alignment). */ #define pool_get(P,E) pool_get_aligned(P,E,0) +/** See if pool_get will expand the pool or not */ +#define pool_get_aligned_will_expand (P,YESNO,A) \ +do { \ + pool_header_t * _pool_var (p) = pool_header (P); \ + uword _pool_var (l); \ + \ + _pool_var (l) = 0; \ + if (P) \ + _pool_var (l) = vec_len (_pool_var (p)->free_indices); \ + \ + /* Free elements, certainly won't expand */ \ + if (_pool_var (l) > 0) \ + YESNO=0; \ + else \ + { \ + /* Nothing on free list, make a new element and return it. */ \ + YESNO = _vec_resize_will_expand \ + (P, \ + /* length_increment */ 1, \ + /* new size */ (vec_len (P) + 1) * sizeof (P[0]), \ + pool_aligned_header_bytes, \ + /* align */ (A)); \ + } \ +} while (0) + +#define pool_get_will_expand(P,YESNO) pool_get_aligned_will_expand(P,YESNO,0) + /** Use free bitmap to query whether given element is free. */ #define pool_is_free(P,E) \ ({ \ -- cgit 1.2.3-korg