diff options
author | Dave Barach <dave@barachs.net> | 2018-10-18 15:37:49 -0400 |
---|---|---|
committer | Damjan Marion <dmarion@me.com> | 2018-10-19 07:06:07 +0000 |
commit | bf3443b0f852f5a4c551d12f926defbd047f2161 (patch) | |
tree | 533966f8461d3c0af618435047f215a85e99aa87 /src/vppinfra/pool.h | |
parent | ecbd20b6e9a2291908bb51a9b708a11eb86010b3 (diff) |
Add pool_get_zero, pool_get_aligned_zero macros
Shorthand for the pattern:
pool_get (<pool>, ep);
memset (ep, 0, sizeof(*ep));
Should have done this years ago.
Change-Id: Ideeb27a79ff4ca3e9a077c973b297671d1fa2d26
Signed-off-by: Dave Barach <dave@barachs.net>
Diffstat (limited to 'src/vppinfra/pool.h')
-rw-r--r-- | src/vppinfra/pool.h | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/vppinfra/pool.h b/src/vppinfra/pool.h index 692702247ea..75d4c95ce11 100644 --- a/src/vppinfra/pool.h +++ b/src/vppinfra/pool.h @@ -185,7 +185,7 @@ pool_free_elts (void *v) First search free list. If nothing is free extend vector of objects. */ -#define pool_get_aligned(P,E,A) \ +#define _pool_get_aligned_internal(P,E,A,Z) \ do { \ pool_header_t * _pool_var (p) = pool_header (P); \ uword _pool_var (l); \ @@ -222,11 +222,22 @@ do { \ /* align */ (A)); \ E = vec_end (P) - 1; \ } \ + if (Z) \ + memset(E, 0, sizeof(*E)); \ } while (0) +/** Allocate an object E from a pool P with alignment A */ +#define pool_get_aligned(P,E,A) _pool_get_aligned_internal(P,E,A,0) + +/** Allocate an object E from a pool P with alignment A and zero it */ +#define pool_get_aligned_zero(P,E,A) _pool_get_aligned_internal(P,E,A,1) + /** Allocate an object E from a pool P (unspecified alignment). */ #define pool_get(P,E) pool_get_aligned(P,E,0) +/** Allocate an object E from a pool P and zero it */ +#define pool_get_zero(P,E) pool_get_aligned_zero(P,E,0) + /** See if pool_get will expand the pool or not */ #define pool_get_aligned_will_expand(P,YESNO,A) \ do { \ @@ -257,6 +268,7 @@ do { \ } \ } while (0) +/** Tell the caller if pool get will expand the pool */ #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. */ |