1 /*
2  * Copyright 2018 The Hafnium Authors.
3  *
4  * Use of this source code is governed by a BSD-style
5  * license that can be found in the LICENSE file or at
6  * https://opensource.org/licenses/BSD-3-Clause.
7  */
8 
9 #pragma once
10 
11 #include <stdbool.h>
12 #include <stddef.h>
13 
14 #include "hf/spinlock.h"
15 
16 struct mpool {
17 	struct spinlock lock;
18 	size_t entry_size;
19 	struct mpool_chunk *chunk_list;
20 	struct mpool_entry *entry_list;
21 	struct mpool *fallback;
22 };
23 
24 void mpool_enable_locks(void);
25 void mpool_init(struct mpool *p, size_t entry_size);
26 void mpool_init_from(struct mpool *p, struct mpool *from);
27 void mpool_init_with_fallback(struct mpool *p, struct mpool *fallback);
28 void mpool_fini(struct mpool *p);
29 bool mpool_add_chunk(struct mpool *p, void *begin, size_t size);
30 void *mpool_alloc(struct mpool *p);
31 void *mpool_alloc_contiguous(struct mpool *p, size_t count, size_t align);
32 void mpool_free(struct mpool *p, void *ptr);
33