From f9ecec856441c53025031dbd2c5941aa579d04e2 Mon Sep 17 00:00:00 2001 From: Radkesvat <134321679+radkesvat@users.noreply.github.com> Date: Fri, 16 Aug 2024 12:00:31 +0000 Subject: [PATCH] improvements --- ww/master_pool.h | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/ww/master_pool.h b/ww/master_pool.h index 869756d..fb48bdb 100644 --- a/ww/master_pool.h +++ b/ww/master_pool.h @@ -53,6 +53,7 @@ struct master_pool_s; typedef void master_pool_item_t; +// pool handles are assumed to be thread safe typedef master_pool_item_t *(*MasterPoolItemCreateHandle)(struct master_pool_s *pool, void *userdata); typedef void (*MasterPoolItemDestroyHandle)(struct master_pool_s *pool, master_pool_item_t *item, void *userdata); @@ -79,13 +80,13 @@ static inline void popMasterPoolItems(master_pool_t *const pool, master_pool_ite // iptr[i] = pool->create_item_handle(pool, userdata); // } // return; + unsigned int i = 0; if (atomic_load_explicit(&(pool->len), memory_order_relaxed) > 0) { hhybridmutex_lock(&(pool->mutex)); const unsigned int tmp_len = atomic_load_explicit(&(pool->len), memory_order_relaxed); const unsigned int consumed = min(tmp_len, count); - unsigned int i = 0; if (consumed > 0) { @@ -96,16 +97,10 @@ static inline void popMasterPoolItems(master_pool_t *const pool, master_pool_ite iptr[i] = pool->available[pbase + i]; } } - for (; i < count; i++) - { - iptr[i] = pool->create_item_handle(pool, userdata); - } - hhybridmutex_unlock(&(pool->mutex)); - return; } - for (unsigned int i = 0; i < count; i++) + for (; i < count; i++) { iptr[i] = pool->create_item_handle(pool, userdata); } @@ -129,11 +124,12 @@ static inline void reuseMasterPoolItems(master_pool_t *const pool, master_pool_i return; } + unsigned int i = 0; + hhybridmutex_lock(&(pool->mutex)); const unsigned int tmp_len = atomic_load_explicit(&(pool->len), memory_order_relaxed); const unsigned int consumed = min(pool->cap - tmp_len, count); - unsigned int i = 0; atomic_fetch_add_explicit(&(pool->len), consumed, memory_order_relaxed); @@ -142,12 +138,12 @@ static inline void reuseMasterPoolItems(master_pool_t *const pool, master_pool_i pool->available[i + tmp_len] = iptr[i]; } + hhybridmutex_unlock(&(pool->mutex)); + for (; i < count; i++) { pool->destroy_item_handle(pool, iptr[i], userdata); } - - hhybridmutex_unlock(&(pool->mutex)); } static void installMasterPoolAllocCallbacks(master_pool_t *pool, MasterPoolItemCreateHandle create_h,