2020-11-09 05:23:58 +01:00
|
|
|
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
2014-08-12 23:35:23 +02:00
|
|
|
#pragma once
|
|
|
|
|
2018-10-09 16:02:55 +02:00
|
|
|
#include <stdbool.h>
|
2014-08-12 23:35:23 +02:00
|
|
|
#include <stddef.h>
|
|
|
|
|
|
|
|
struct pool;
|
|
|
|
|
|
|
|
struct mempool {
|
|
|
|
struct pool *first_pool;
|
|
|
|
void *freelist;
|
|
|
|
size_t tile_size;
|
|
|
|
unsigned at_least;
|
|
|
|
};
|
|
|
|
|
|
|
|
void* mempool_alloc_tile(struct mempool *mp);
|
2014-10-24 15:30:18 +02:00
|
|
|
void* mempool_alloc0_tile(struct mempool *mp);
|
2014-08-12 23:35:23 +02:00
|
|
|
void mempool_free_tile(struct mempool *mp, void *p);
|
|
|
|
|
|
|
|
#define DEFINE_MEMPOOL(pool_name, tile_type, alloc_at_least) \
|
2016-02-13 12:28:28 +01:00
|
|
|
static struct mempool pool_name = { \
|
2014-08-12 23:35:23 +02:00
|
|
|
.tile_size = sizeof(tile_type), \
|
|
|
|
.at_least = alloc_at_least, \
|
|
|
|
}
|
|
|
|
|
2018-10-09 16:02:55 +02:00
|
|
|
extern const bool mempool_use_allowed;
|
2018-10-09 15:53:35 +02:00
|
|
|
bool mempool_enabled(void);
|
|
|
|
|
2018-05-13 22:28:24 +02:00
|
|
|
#if VALGRIND
|
2014-08-12 23:35:23 +02:00
|
|
|
void mempool_drop(struct mempool *mp);
|
|
|
|
#endif
|