diff --git a/include/ck_bag.h b/include/ck_bag.h index 2f7e4e4..581c844 100644 --- a/include/ck_bag.h +++ b/include/ck_bag.h @@ -53,9 +53,7 @@ /* - * Memory Allocation Strategies: - * GEOMETRIC = allocate # of existing blocks * 2. - * LINEAR = only allocate a single block. + * Growth strategies */ enum ck_bag_allocation_strategy { CK_BAG_ALLOCATE_GEOMETRIC = 0, @@ -63,9 +61,9 @@ enum ck_bag_allocation_strategy { }; /* - * max: max n_entries per block - * bytes: sizeof(ck_bag_block) + sizeof(flex. array member) - * + inline allocator overhead + * max: max n_entries per block + * bytes: sizeof(ck_bag_block) + sizeof(flex. array member) + * + inline allocator overhead */ struct ck_bag_block_info { size_t max; @@ -87,7 +85,6 @@ struct ck_bag_block { struct ck_bag_block_md next; struct ck_bag_block *avail_next; struct ck_bag_block *avail_prev; - void *array[]; } CK_CC_CACHELINE; @@ -167,9 +164,11 @@ ck_bag_next(struct ck_bag_iterator *iterator, void **entry) iterator->block = ck_bag_block_next(next); n_entries = (iterator->block != NULL) ? ck_bag_block_count(iterator->block) : 0; + if (n_entries == 0) return false; + ck_pr_load_fence(); iterator->index = 0; iterator->n_entries = n_entries; } diff --git a/include/ck_md.h b/include/ck_md.h index 33c5a69..4e620df 100644 --- a/include/ck_md.h +++ b/include/ck_md.h @@ -31,8 +31,8 @@ #define CK_MD_CACHELINE (64) #endif -#ifndef CK_MD_PAGE_SIZE -#define CK_MD_PAGE_SIZE (4096) +#ifndef CK_MD_PAGESIZE +#define CK_MD_PAGESIZE (4096) #endif #endif /* _CK_MD_H */ diff --git a/src/ck_bag.c b/src/ck_bag.c index 490619f..a9266bb 100644 --- a/src/ck_bag.c +++ b/src/ck_bag.c @@ -39,7 +39,9 @@ #define CK_BAG_CL_SIZE CK_MD_CACHELINE #endif -#define CK_BAG_PAGE_SIZE CK_MD_PAGE_SIZE +#ifndef CK_BAG_PAGESIZE +#define CK_BAG_PAGESIZE CK_MD_PAGESIZE +#endif #define CK_BAG_MAX_N_ENTRIES (1 << 12) @@ -48,13 +50,10 @@ static size_t allocator_overhead; bool ck_bag_init(struct ck_bag *bag, - size_t n_block_entries, - enum ck_bag_allocation_strategy as) + size_t n_block_entries, + enum ck_bag_allocation_strategy as) { - size_t block_overhead; - if (bag == NULL) - return false; bag->avail_head = bag->avail_tail = NULL; bag->head = NULL; @@ -73,7 +72,7 @@ ck_bag_init(struct ck_bag *bag, block_overhead = sizeof(struct ck_bag_block) + allocator_overhead; if (n_block_entries == CK_BAG_DEFAULT) { - bag->info.max = ((CK_BAG_PAGE_SIZE - block_overhead) / sizeof(void *)); + bag->info.max = ((CK_BAG_PAGESIZE - block_overhead) / sizeof(void *)); } else { bag->info.max = ((CK_BAG_CL_SIZE - block_overhead) / sizeof(void *)); if (n_block_entries > bag->info.max) @@ -115,7 +114,6 @@ ck_bag_allocator_set(struct ck_malloc *m, size_t alloc_overhead) bool ck_bag_put_spmc(struct ck_bag *bag, void *entry) { - struct ck_bag_block *cursor, *new_block, *new_block_prev, *new_tail; uint16_t n_entries_block; size_t blocks_alloc, i; @@ -248,7 +246,6 @@ ck_bag_put_spmc(struct ck_bag *bag, void *entry) bool ck_bag_set_spmc(struct ck_bag *bag, void *compare, void *update) { - struct ck_bag_block *cursor; uint16_t block_index; uint16_t n_entries_block = 0;