From 007aa328fcf973b47fcfd8225ab9077cb3c45145 Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Mon, 23 Jan 2023 16:54:36 -0800 Subject: Format. --- listpool/include/listpool.h | 57 +++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 28 deletions(-) (limited to 'listpool/include') diff --git a/listpool/include/listpool.h b/listpool/include/listpool.h index a5e4955..1711449 100644 --- a/listpool/include/listpool.h +++ b/listpool/include/listpool.h @@ -7,11 +7,11 @@ #include /// Define a typed listpool of a given size. -#define DEF_LISTPOOL(POOL, TYPE, NUM_BLOCKS) \ - typedef struct POOL { \ - listpool pool; \ - list nodes[NUM_BLOCKS]; \ - TYPE blocks[NUM_BLOCKS]; \ +#define DEF_LISTPOOL(POOL, TYPE, NUM_BLOCKS) \ + typedef struct POOL { \ + listpool pool; \ + list nodes[NUM_BLOCKS]; \ + TYPE blocks[NUM_BLOCKS]; \ } POOL; /// Creates a new listpool. @@ -20,8 +20,8 @@ assert(POOL); \ const size_t block_size = sizeof((POOL)->blocks[0]); \ const size_t num_blocks = sizeof((POOL)->blocks) / block_size; \ - listpool_make_(&(POOL)->pool, (POOL)->nodes, (POOL)->blocks, num_blocks, \ - block_size); \ + listpool_make_( \ + &(POOL)->pool, (POOL)->nodes, (POOL)->blocks, num_blocks, block_size); \ } /// Allocate a new block. @@ -35,31 +35,31 @@ /// Remove a value from the list. /// Defined here instead of DEF_LISTPOOL_IMPL() because not all types may have /// an operator==. -#define listpool_remove(POOL, VAL) \ - { \ - listpool_foreach(POOL, iter, { \ - if (*iter == VAL) { \ - listpool_free(POOL, &iter); \ - break; \ - } \ - }); \ +#define listpool_remove(POOL, VAL) \ + { \ + listpool_foreach(POOL, iter, { \ + if (*iter == VAL) { \ + listpool_free(POOL, &iter); \ + break; \ + } \ + }); \ } /// Iterate over the used items of the pool. -#define listpool_foreach(POOL, ITER, BODY) \ - for (list* it_ = (POOL)->pool.used; it_; it_ = it_->next) { \ - typeof((POOL)->blocks[0])* ITER = \ - &(POOL)->blocks[it_ - (POOL)->pool.nodes]; \ - (void)ITER; \ - BODY; \ +#define listpool_foreach(POOL, ITER, BODY) \ + for (list* it_ = (POOL)->pool.used; it_; it_ = it_->next) { \ + typeof((POOL)->blocks[0])* ITER = \ + &(POOL)->blocks[it_ - (POOL)->pool.nodes]; \ + (void)ITER; \ + BODY; \ } typedef struct listpool { - size_t block_size_bytes; - size_t num_blocks; - list* free; // Head of the free list. - list* used; // Head of the used list. - list* nodes; // Array of nodes. + size_t block_size_bytes; + size_t num_blocks; + list* free; // Head of the free list. + list* used; // Head of the used list. + list* nodes; // Array of nodes. uint8_t* blocks; // Array of blocks; } listpool; @@ -67,8 +67,9 @@ typedef struct listpool { /// `nodes` must have at least `num_blocks` nodes. /// `blocks` must be at least `num_blocks` * `block_size_bytes` bytes. /// All blocks are zeroed out for convenience. -void listpool_make_(listpool* pool, list* nodes, void* blocks, - size_t num_blocks, size_t block_size_bytes); +void listpool_make_( + listpool* pool, list* nodes, void* blocks, size_t num_blocks, + size_t block_size_bytes); /// Allocate a new block. /// Return 0 if there is no memory left. -- cgit v1.2.3