X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvppinfra%2Fpool.h;h=692702247ea0e9462be60bf5f5b419c6c7fa9d4d;hb=ec11b13a21b2becc1d1bd746a04624d17b26583f;hp=14c6a75c13b3b6b16af14c64b0fd3893c16eda75;hpb=87bd96aa4ddf2f777f8b972062c205e27addbc4a;p=vpp.git diff --git a/src/vppinfra/pool.h b/src/vppinfra/pool.h index 14c6a75c13b..692702247ea 100644 --- a/src/vppinfra/pool.h +++ b/src/vppinfra/pool.h @@ -190,6 +190,8 @@ do { \ pool_header_t * _pool_var (p) = pool_header (P); \ uword _pool_var (l); \ \ + STATIC_ASSERT(A==0 || ((A % sizeof(P[0]))==0) || ((sizeof(P[0]) % A) == 0), \ + "Pool aligned alloc of incorrectly sized object"); \ _pool_var (l) = 0; \ if (P) \ _pool_var (l) = vec_len (_pool_var (p)->free_indices); \ @@ -199,8 +201,9 @@ do { \ /* Return free element from free list. */ \ uword _pool_var (i) = _pool_var (p)->free_indices[_pool_var (l) - 1]; \ (E) = (P) + _pool_var (i); \ - _pool_var (p)->free_bitmap = \ - clib_bitmap_andnoti (_pool_var (p)->free_bitmap, _pool_var (i)); \ + _pool_var (p)->free_bitmap = \ + clib_bitmap_andnoti_notrim (_pool_var (p)->free_bitmap, \ + _pool_var (i)); \ _vec_len (_pool_var (p)->free_indices) = _pool_var (l) - 1; \ } \ else \ @@ -218,7 +221,7 @@ do { \ pool_aligned_header_bytes, \ /* align */ (A)); \ E = vec_end (P) - 1; \ - } \ + } \ } while (0) /** Allocate an object E from a pool P (unspecified alignment). */ @@ -277,7 +280,9 @@ do { \ \ /* Add element to free bitmap and to free list. */ \ _pool_var (p)->free_bitmap = \ - clib_bitmap_ori (_pool_var (p)->free_bitmap, _pool_var (l)); \ + clib_bitmap_ori_notrim (_pool_var (p)->free_bitmap, \ + _pool_var (l)); \ + \ /* Preallocated pool? */ \ if (_pool_var (p)->max_elts) \ { \ @@ -473,6 +478,9 @@ do { \ (_pool_var (rv) < vec_len (P) ? \ clib_bitmap_next_clear (_pool_var (p)->free_bitmap, _pool_var(rv)) \ : ~0); \ + _pool_var(rv) = \ + (_pool_var (rv) < vec_len (P) ? \ + _pool_var (rv) : ~0); \ _pool_var(rv); \ }) @@ -485,7 +493,7 @@ do { \ } /** - * @brief Remove all elemenets from a pool in a safe way + * @brief Remove all elements from a pool in a safe way * * @param VAR each element in the pool * @param POOL The pool to flush