ck_bag: Various stylistics changes, ck_md: Rename CK_MD_PAGE_SIZE to CK_MD_PAGESIZE.

ck_pring
Samy Al Bahra 13 years ago
parent 8e83963d63
commit f940cc1263

@ -53,9 +53,7 @@
/* /*
* Memory Allocation Strategies: * Growth strategies
* GEOMETRIC = allocate # of existing blocks * 2.
* LINEAR = only allocate a single block.
*/ */
enum ck_bag_allocation_strategy { enum ck_bag_allocation_strategy {
CK_BAG_ALLOCATE_GEOMETRIC = 0, CK_BAG_ALLOCATE_GEOMETRIC = 0,
@ -63,9 +61,9 @@ enum ck_bag_allocation_strategy {
}; };
/* /*
* max: max n_entries per block * max: max n_entries per block
* bytes: sizeof(ck_bag_block) + sizeof(flex. array member) * bytes: sizeof(ck_bag_block) + sizeof(flex. array member)
* + inline allocator overhead * + inline allocator overhead
*/ */
struct ck_bag_block_info { struct ck_bag_block_info {
size_t max; size_t max;
@ -87,7 +85,6 @@ struct ck_bag_block {
struct ck_bag_block_md next; struct ck_bag_block_md next;
struct ck_bag_block *avail_next; struct ck_bag_block *avail_next;
struct ck_bag_block *avail_prev; struct ck_bag_block *avail_prev;
void *array[]; void *array[];
} CK_CC_CACHELINE; } CK_CC_CACHELINE;
@ -167,9 +164,11 @@ ck_bag_next(struct ck_bag_iterator *iterator, void **entry)
iterator->block = ck_bag_block_next(next); iterator->block = ck_bag_block_next(next);
n_entries = (iterator->block != NULL) ? n_entries = (iterator->block != NULL) ?
ck_bag_block_count(iterator->block) : 0; ck_bag_block_count(iterator->block) : 0;
if (n_entries == 0) if (n_entries == 0)
return false; return false;
ck_pr_load_fence();
iterator->index = 0; iterator->index = 0;
iterator->n_entries = n_entries; iterator->n_entries = n_entries;
} }

@ -31,8 +31,8 @@
#define CK_MD_CACHELINE (64) #define CK_MD_CACHELINE (64)
#endif #endif
#ifndef CK_MD_PAGE_SIZE #ifndef CK_MD_PAGESIZE
#define CK_MD_PAGE_SIZE (4096) #define CK_MD_PAGESIZE (4096)
#endif #endif
#endif /* _CK_MD_H */ #endif /* _CK_MD_H */

@ -39,7 +39,9 @@
#define CK_BAG_CL_SIZE CK_MD_CACHELINE #define CK_BAG_CL_SIZE CK_MD_CACHELINE
#endif #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) #define CK_BAG_MAX_N_ENTRIES (1 << 12)
@ -48,13 +50,10 @@ static size_t allocator_overhead;
bool bool
ck_bag_init(struct ck_bag *bag, ck_bag_init(struct ck_bag *bag,
size_t n_block_entries, size_t n_block_entries,
enum ck_bag_allocation_strategy as) enum ck_bag_allocation_strategy as)
{ {
size_t block_overhead; size_t block_overhead;
if (bag == NULL)
return false;
bag->avail_head = bag->avail_tail = NULL; bag->avail_head = bag->avail_tail = NULL;
bag->head = NULL; bag->head = NULL;
@ -73,7 +72,7 @@ ck_bag_init(struct ck_bag *bag,
block_overhead = sizeof(struct ck_bag_block) + allocator_overhead; block_overhead = sizeof(struct ck_bag_block) + allocator_overhead;
if (n_block_entries == CK_BAG_DEFAULT) { 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 { } else {
bag->info.max = ((CK_BAG_CL_SIZE - block_overhead) / sizeof(void *)); bag->info.max = ((CK_BAG_CL_SIZE - block_overhead) / sizeof(void *));
if (n_block_entries > bag->info.max) if (n_block_entries > bag->info.max)
@ -115,7 +114,6 @@ ck_bag_allocator_set(struct ck_malloc *m, size_t alloc_overhead)
bool bool
ck_bag_put_spmc(struct ck_bag *bag, void *entry) ck_bag_put_spmc(struct ck_bag *bag, void *entry)
{ {
struct ck_bag_block *cursor, *new_block, *new_block_prev, *new_tail; struct ck_bag_block *cursor, *new_block, *new_block_prev, *new_tail;
uint16_t n_entries_block; uint16_t n_entries_block;
size_t blocks_alloc, i; size_t blocks_alloc, i;
@ -248,7 +246,6 @@ ck_bag_put_spmc(struct ck_bag *bag, void *entry)
bool bool
ck_bag_set_spmc(struct ck_bag *bag, void *compare, void *update) ck_bag_set_spmc(struct ck_bag *bag, void *compare, void *update)
{ {
struct ck_bag_block *cursor; struct ck_bag_block *cursor;
uint16_t block_index; uint16_t block_index;
uint16_t n_entries_block = 0; uint16_t n_entries_block = 0;

Loading…
Cancel
Save