aboutsummaryrefslogtreecommitdiffstats
path: root/src/vppinfra
diff options
context:
space:
mode:
Diffstat (limited to 'src/vppinfra')
-rw-r--r--src/vppinfra/bitmap.h4
-rw-r--r--src/vppinfra/pool.h87
-rw-r--r--src/vppinfra/vec.c6
-rw-r--r--src/vppinfra/vec.h37
4 files changed, 44 insertions, 90 deletions
diff --git a/src/vppinfra/bitmap.h b/src/vppinfra/bitmap.h
index 459e6f2b9b4..096d3f1aa4a 100644
--- a/src/vppinfra/bitmap.h
+++ b/src/vppinfra/bitmap.h
@@ -208,9 +208,7 @@ clib_bitmap_set (uword * ai, uword i, uword value)
always_inline u8
clib_bitmap_will_expand (uword *ai, uword i)
{
- uword i0 = i / BITS (ai[0]);
- return _vec_resize_will_expand (ai, 1, i0 * sizeof (ai[0]), 0,
- sizeof (uword));
+ return (i / BITS (ai[0])) < vec_max_len (ai);
}
/** Gets the ith bit value from a bitmap
diff --git a/src/vppinfra/pool.h b/src/vppinfra/pool.h
index 9fca6562716..7a679cee5cb 100644
--- a/src/vppinfra/pool.h
+++ b/src/vppinfra/pool.h
@@ -249,57 +249,46 @@ do { \
/** 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 { \
- pool_header_t * _pool_var (p) = pool_header (P); \
- uword _pool_var (l); \
- \
- _pool_var (l) = 0; \
- if (P) \
- { \
- if (_pool_var (p)->max_elts) \
- _pool_var (l) = _pool_var (p)->max_elts; \
- else \
- _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)
+always_inline int
+_pool_get_will_expand (void *p, uword elt_size)
+{
+ pool_header_t *ph;
+ uword len;
-/** See if pool_put will expand free_bitmap or free_indices or not */
-#define pool_put_will_expand(P, E, YESNO) \
- do \
- { \
- pool_header_t *_pool_var (p) = pool_header (P); \
- \
- uword _pool_var (i) = (E) - (P); \
- /* free_bitmap or free_indices may expand. */ \
- YESNO = \
- clib_bitmap_will_expand (_pool_var (p)->free_bitmap, _pool_var (i)); \
- \
- YESNO += _vec_resize_will_expand ( \
- _pool_var (p)->free_indices, 1, \
- (vec_len (_pool_var (p)->free_indices) + 1) * \
- sizeof (_pool_var (p)->free_indices[0]), \
- 0, 0); \
- } \
- while (0)
+ if (p == 0)
+ return 1;
+
+ ph = pool_header (p);
+
+ if (ph->max_elts)
+ len = ph->max_elts;
+ else
+ len = vec_len (ph->free_indices);
+
+ /* Free elements, certainly won't expand */
+ if (len > 0)
+ return 0;
+
+ return _vec_resize_will_expand (p, 1, elt_size);
+}
+
+#define pool_get_will_expand(P) _pool_get_will_expand (P, sizeof ((P)[0]))
+
+always_inline int
+_pool_put_will_expand (void *p, uword index, uword elt_size)
+{
+ pool_header_t *ph = pool_header (p);
+
+ if (clib_bitmap_will_expand (ph->free_bitmap, index))
+ return 1;
+
+ if (vec_resize_will_expand (ph->free_indices, 1))
+ return 1;
+
+ return 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)
+#define pool_put_will_expand(P, E) _pool_put_will_expand (P, (E) - (P), sizeof ((P)[0])
/** Use free bitmap to query whether given element is free. */
#define pool_is_free(P,E) \
diff --git a/src/vppinfra/vec.c b/src/vppinfra/vec.c
index db84c1463a0..ba842e64d25 100644
--- a/src/vppinfra/vec.c
+++ b/src/vppinfra/vec.c
@@ -151,12 +151,6 @@ vec_resize_allocate_memory (void *v,
return v + header_bytes;
}
-__clib_export uword
-clib_mem_is_vec_h (void *v, uword header_bytes)
-{
- return clib_mem_is_heap_object (vec_header (v));
-}
-
__clib_export u32
vec_len_not_inline (void *v)
{
diff --git a/src/vppinfra/vec.h b/src/vppinfra/vec.h
index 3f50bd25625..7e4cc0f8959 100644
--- a/src/vppinfra/vec.h
+++ b/src/vppinfra/vec.h
@@ -184,26 +184,14 @@ _vec_resize_inline (void *v,
*/
always_inline int
-_vec_resize_will_expand (void *v,
- word length_increment,
- uword data_bytes, uword header_bytes,
- uword data_align)
+_vec_resize_will_expand (void *v, uword n_elts, uword elt_size)
{
- uword new_data_bytes, aligned_header_bytes;
-
- aligned_header_bytes = vec_header_bytes (header_bytes);
-
- new_data_bytes = data_bytes + aligned_header_bytes;
-
if (PREDICT_TRUE (v != 0))
{
- void *p = v - aligned_header_bytes;
-
/* Vector header must start heap object. */
- ASSERT (clib_mem_is_heap_object (p));
+ ASSERT (clib_mem_is_heap_object (vec_header (v)));
- /* Typically we'll not need to resize. */
- if (new_data_bytes <= clib_mem_size (p))
+ if (vec_mem_size (v) >= ((_vec_len (v) + n_elts)) * elt_size)
return 0;
}
return 1;
@@ -217,22 +205,7 @@ _vec_resize_will_expand (void *v,
*/
#define vec_resize_will_expand(V, N) \
- ({ \
- word _v (n) = (N); \
- word _v (l) = vec_len (V); \
- _vec_resize_will_expand ((V), _v (n), \
- (_v (l) + _v (n)) * sizeof ((V)[0]), 0, 0); \
- })
-
-/** \brief Predicate function, says whether the supplied vector is a clib heap
- object (general version).
-
- @param v pointer to a vector
- @param header_bytes vector header size in bytes (may be zero)
- @return 0 or 1
-*/
-uword clib_mem_is_vec_h (void *v, uword header_bytes);
-
+ _vec_resize_will_expand (V, N, sizeof ((V)[0]))
/** \brief Predicate function, says whether the supplied vector is a clib heap
object
@@ -243,7 +216,7 @@ uword clib_mem_is_vec_h (void *v, uword header_bytes);
always_inline uword
clib_mem_is_vec (void *v)
{
- return clib_mem_is_vec_h (v, 0);
+ return clib_mem_is_heap_object (vec_header (v));
}
/* Local variable naming macro (prevents collisions with other macro naming). */