Wedson Almeida Filho | 11a9b0b | 2018-11-30 18:21:51 +0000 | [diff] [blame] | 1 | /* |
Andrew Walbran | 692b325 | 2019-03-07 15:51:31 +0000 | [diff] [blame] | 2 | * Copyright 2018 The Hafnium Authors. |
Wedson Almeida Filho | 11a9b0b | 2018-11-30 18:21:51 +0000 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #pragma once |
| 18 | |
| 19 | #include <stdbool.h> |
| 20 | #include <stddef.h> |
| 21 | |
| 22 | #include "hf/spinlock.h" |
| 23 | |
| 24 | struct mpool { |
| 25 | struct spinlock lock; |
| 26 | size_t entry_size; |
| 27 | struct mpool_chunk *chunk_list; |
| 28 | struct mpool_entry *entry_list; |
Andrew Scull | 63d1f3f | 2018-12-06 13:29:10 +0000 | [diff] [blame] | 29 | struct mpool *fallback; |
Wedson Almeida Filho | 11a9b0b | 2018-11-30 18:21:51 +0000 | [diff] [blame] | 30 | }; |
| 31 | |
| 32 | void mpool_enable_locks(void); |
| 33 | void mpool_init(struct mpool *p, size_t entry_size); |
| 34 | void mpool_init_from(struct mpool *p, struct mpool *from); |
Andrew Scull | 63d1f3f | 2018-12-06 13:29:10 +0000 | [diff] [blame] | 35 | void mpool_init_with_fallback(struct mpool *p, struct mpool *fallback); |
| 36 | void mpool_fini(struct mpool *p); |
Wedson Almeida Filho | 11a9b0b | 2018-11-30 18:21:51 +0000 | [diff] [blame] | 37 | bool mpool_add_chunk(struct mpool *p, void *begin, size_t size); |
| 38 | void *mpool_alloc(struct mpool *p); |
| 39 | void *mpool_alloc_contiguous(struct mpool *p, size_t count, size_t align); |
| 40 | void mpool_free(struct mpool *p, void *ptr); |