blob: 0034dbbe7f8238a43e312f2707120e78a5160f7e [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;
Andrew Scull63d1f3f2018-12-06 13:29:10 +000029 struct mpool *fallback;
Wedson Almeida Filho11a9b0b2018-11-30 18:21:51 +000030};
31
32void mpool_enable_locks(void);
33void mpool_init(struct mpool *p, size_t entry_size);
34void mpool_init_from(struct mpool *p, struct mpool *from);
Andrew Scull63d1f3f2018-12-06 13:29:10 +000035void mpool_init_with_fallback(struct mpool *p, struct mpool *fallback);
36void mpool_fini(struct mpool *p);
Wedson Almeida Filho11a9b0b2018-11-30 18:21:51 +000037bool mpool_add_chunk(struct mpool *p, void *begin, size_t size);
38void *mpool_alloc(struct mpool *p);
39void *mpool_alloc_contiguous(struct mpool *p, size_t count, size_t align);
40void mpool_free(struct mpool *p, void *ptr);