]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/mempool.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 Copyright 2010-2014 Lennart Poettering
4 Copyright 2014 Michal Schmidt
20 void* mempool_alloc_tile(struct mempool
*mp
) {
23 /* When a tile is released we add it to the list and simply
24 * place the next pointer at its offset 0. */
26 assert(mp
->tile_size
>= sizeof(void*));
27 assert(mp
->at_least
> 0);
33 mp
->freelist
= * (void**) mp
->freelist
;
37 if (_unlikely_(!mp
->first_pool
) ||
38 _unlikely_(mp
->first_pool
->n_used
>= mp
->first_pool
->n_tiles
)) {
42 n
= mp
->first_pool
? mp
->first_pool
->n_tiles
: 0;
43 n
= MAX(mp
->at_least
, n
* 2);
44 size
= PAGE_ALIGN(ALIGN(sizeof(struct pool
)) + n
*mp
->tile_size
);
45 n
= (size
- ALIGN(sizeof(struct pool
))) / mp
->tile_size
;
51 p
->next
= mp
->first_pool
;
58 i
= mp
->first_pool
->n_used
++;
60 return ((uint8_t*) mp
->first_pool
) + ALIGN(sizeof(struct pool
)) + i
*mp
->tile_size
;
63 void* mempool_alloc0_tile(struct mempool
*mp
) {
66 p
= mempool_alloc_tile(mp
);
68 memzero(p
, mp
->tile_size
);
72 void mempool_free_tile(struct mempool
*mp
, void *p
) {
73 * (void**) p
= mp
->freelist
;
79 void mempool_drop(struct mempool
*mp
) {
80 struct pool
*p
= mp
->first_pool
;