aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorFlorin Coras <fcoras@cisco.com>2022-03-09 13:34:12 -0800
committerFlorin Coras <fcoras@cisco.com>2022-03-09 14:03:48 -0800
commit400d459bc1cfa9a5089a2bfb942e59e81ec0fdf1 (patch)
treeb81642e8e67595e2acb12081371ddcd9f8aec2a1 /src
parent346c24723b8060c08542ea84921a997c7951ece7 (diff)
vppinfra: fix pool_free_elts
Type: fix Signed-off-by: Florin Coras <fcoras@cisco.com> Change-Id: I3425350f5e874df79716bd726900540629793beb
Diffstat (limited to 'src')
-rw-r--r--src/vppinfra/pool.h37
1 files changed, 18 insertions, 19 deletions
diff --git a/src/vppinfra/pool.h b/src/vppinfra/pool.h
index 3b5a9007f4f..9dd05a382ab 100644
--- a/src/vppinfra/pool.h
+++ b/src/vppinfra/pool.h
@@ -162,27 +162,26 @@ pool_header_bytes (void *v)
/** Local variable naming macro. */
#define _pool_var(v) _pool_##v
-/** Queries whether pool has at least N_FREE free elements. */
-always_inline uword
-pool_free_elts (void *v)
-{
- pool_header_t *p = pool_header (v);
- uword n_free = 0;
+/** Number of bytes that can fit into pool with current allocation */
+#define pool_capacity(P) vec_capacity (P, pool_aligned_header_bytes)
- if (v)
- {
- n_free += vec_len (p->free_indices);
-
- /*
- * Space left at end of vector?
- * Fixed-size pools have max_elts set non-zero,
- */
- if (p->max_elts == 0)
- n_free += vec_capacity (v, sizeof (p[0])) - vec_len (v);
- }
+/** Number of elements that can fit into pool with current allocation */
+#define pool_max_len(P) (pool_capacity (P) / sizeof (P[0]))
- return n_free;
-}
+/** Number of free elements in pool */
+#define pool_free_elts(P) \
+ ({ \
+ pool_header_t *_pool_var (p) = pool_header (P); \
+ uword n_free = 0; \
+ if (P) \
+ { \
+ n_free += vec_len (_pool_var (p)->free_indices); \
+ /* Fixed-size pools have max_elts set non-zero */ \
+ if (_pool_var (p)->max_elts == 0) \
+ n_free += pool_max_len (P) - vec_len (P); \
+ } \
+ n_free; \
+ })
/** Allocate an object E from a pool P (general version).