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

/***
  This file is part of systemd.

7 8
  Copyright 2011-2014 Lennart Poettering
  Copyright 2014 Michal Schmidt
Beniamino Galvani's avatar
Beniamino Galvani committed
9 10
***/

11
#include <stddef.h>
Beniamino Galvani's avatar
Beniamino Galvani committed
12

13
struct pool;
Beniamino Galvani's avatar
Beniamino Galvani committed
14

15 16 17 18 19 20
struct mempool {
        struct pool *first_pool;
        void *freelist;
        size_t tile_size;
        unsigned at_least;
};
Beniamino Galvani's avatar
Beniamino Galvani committed
21

22 23 24
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
25

26
#define DEFINE_MEMPOOL(pool_name, tile_type, alloc_at_least) \
27
static struct mempool pool_name = { \
28 29 30 31 32 33 34 35
        .tile_size = sizeof(tile_type), \
        .at_least = alloc_at_least, \
}


#ifdef VALGRIND
void mempool_drop(struct mempool *mp);
#endif