blob: 556fea9bae631fec96617dd3632524a55b9e454a [file] [log] [blame]
Wedson Almeida Filho11a9b0b2018-11-30 18:21:51 +00001/*
2 * Copyright 2018 Google LLC
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
24struct mpool {
25 struct spinlock lock;
26 size_t entry_size;
27 struct mpool_chunk *chunk_list;
28 struct mpool_entry *entry_list;
29};
30
31void mpool_enable_locks(void);
32void mpool_init(struct mpool *p, size_t entry_size);
33void mpool_init_from(struct mpool *p, struct mpool *from);
34bool mpool_add_chunk(struct mpool *p, void *begin, size_t size);
35void *mpool_alloc(struct mpool *p);
36void *mpool_alloc_contiguous(struct mpool *p, size_t count, size_t align);
37void mpool_free(struct mpool *p, void *ptr);