mempool.h 611 Bytes
Newer Older
1
/* SPDX-License-Identifier: LGPL-2.1+ */
Beniamino Galvani's avatar
Beniamino Galvani committed
2 3
#pragma once

4
#include <stddef.h>
Beniamino Galvani's avatar
Beniamino Galvani committed
5

6
struct pool;
Beniamino Galvani's avatar
Beniamino Galvani committed
7

8 9 10 11 12 13
struct mempool {
        struct pool *first_pool;
        void *freelist;
        size_t tile_size;
        unsigned at_least;
};
Beniamino Galvani's avatar
Beniamino Galvani committed
14

15 16 17
void* mempool_alloc_tile(struct mempool *mp);
void* mempool_alloc0_tile(struct mempool *mp);
void mempool_free_tile(struct mempool *mp, void *p);
Beniamino Galvani's avatar
Beniamino Galvani committed
18

19
#define DEFINE_MEMPOOL(pool_name, tile_type, alloc_at_least) \
20
static struct mempool pool_name = { \
21 22 23 24
        .tile_size = sizeof(tile_type), \
        .at_least = alloc_at_least, \
}

25
#if VALGRIND
26 27
void mempool_drop(struct mempool *mp);
#endif