summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorFlorin Coras <fcoras@cisco.com>2018-11-27 17:11:37 -0800
committerOle Trøan <otroan@employees.org>2018-11-29 08:43:00 +0000
commit8be6c40cf39f0d637a9dbfaa40ccec1d72bff34a (patch)
treeb2ea554ac45e2c8a364cd0c702c8984f24cca434 /src
parent330bf9387bc8c07547154a5092d4125da684e263 (diff)
vppinfra: add pool_dup macro
Change-Id: I192e340bd072d27bf6ddc382347ad5c3ca411bad Signed-off-by: Florin Coras <fcoras@cisco.com>
Diffstat (limited to 'src')
-rw-r--r--src/vppinfra/pool.h35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/vppinfra/pool.h b/src/vppinfra/pool.h
index 75d4c95ce11..47bae07add0 100644
--- a/src/vppinfra/pool.h
+++ b/src/vppinfra/pool.h
@@ -340,6 +340,41 @@ do { \
/** Allocate N more free elements to pool (unspecified alignment). */
#define pool_alloc(P,N) pool_alloc_aligned(P,N,0)
+/**
+ * Return copy of pool with alignment
+ *
+ * @param P pool to copy
+ * @param A alignment (may be zero)
+ * @return copy of pool
+ */
+#define pool_dup_aligned(P,A) \
+({ \
+ typeof (P) _pool_var (new) = 0; \
+ pool_header_t * _pool_var (ph), * _pool_var (new_ph); \
+ u32 _pool_var (n) = pool_len (P); \
+ _pool_var (new) = _vec_resize (_pool_var (new), _pool_var (n), \
+ _pool_var (n) * sizeof ((P)[0]), \
+ pool_aligned_header_bytes, (A)); \
+ clib_memcpy_fast (_pool_var (new), (P), \
+ _pool_var (n) * sizeof ((P)[0])); \
+ _pool_var (ph) = pool_header (P); \
+ _pool_var (new_ph) = pool_header (_pool_var (new)); \
+ _pool_var (new_ph)->free_bitmap = \
+ clib_bitmap_dup (_pool_var (ph)->free_bitmap); \
+ _pool_var (new_ph)->free_indices = \
+ vec_dup (_pool_var (ph)->free_indices); \
+ _pool_var (new_ph)->max_elts = _pool_var (ph)->max_elts; \
+ _pool_var (new); \
+})
+
+/**
+ * Return copy of pool without alignment
+ *
+ * @param P pool to copy
+ * @return copy of pool
+ */
+#define pool_dup(P) pool_dup_aligned(P, 0)
+
/** Low-level free pool operator (do not call directly). */
always_inline void *
_pool_free (void *v)