Skip to content

Commit

Permalink
improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
radkesvat committed Aug 16, 2024
1 parent 498c677 commit f9ecec8
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions ww/master_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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)
{
Expand All @@ -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);
}
Expand All @@ -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);

Expand All @@ -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,
Expand Down

0 comments on commit f9ecec8

Please sign in to comment.