summaryrefslogtreecommitdiff
path: root/third_party/cherrymp/chry_mempool.h
blob: 8a15bb2c0015eae378600a653f23d7d5561a46d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
 * Copyright (c) 2024, sakumisu
 *
 * SPDX-License-Identifier: Apache-2.0
 */
#ifndef CHRY_MEMPOOL_H
#define CHRY_MEMPOOL_H

#include <stdint.h>
#include <string.h>
#include <stdbool.h>

#include "chry_ringbuffer.h"

typedef void *chry_mempool_osal_sem_t;

struct chry_mempool {
    chry_ringbuffer_t in;
    chry_ringbuffer_t out;
    chry_mempool_osal_sem_t out_sem;

    void *block;
    uint32_t block_size;
    uint32_t block_count;
};

#ifdef __cplusplus
extern "C" {
#endif

chry_mempool_osal_sem_t chry_mempool_osal_sem_create(uint32_t max_count);
void chry_mempool_osal_sem_delete(chry_mempool_osal_sem_t sem);
int chry_mempool_osal_sem_take(chry_mempool_osal_sem_t sem, uint32_t timeout);
int chry_mempool_osal_sem_give(chry_mempool_osal_sem_t sem);
void *chry_mempool_osal_malloc(size_t size);
void chry_mempool_osal_free(void *ptr);

int chry_mempool_create(struct chry_mempool *pool, void *block, uint32_t block_size, uint32_t block_count);
uintptr_t *chry_mempool_alloc(struct chry_mempool *pool);
int chry_mempool_free(struct chry_mempool *pool, uintptr_t *item);
int chry_mempool_send(struct chry_mempool *pool, uintptr_t *item);
int chry_mempool_recv(struct chry_mempool *pool, uintptr_t **item, uint32_t timeout);
void chry_mempool_reset(struct chry_mempool *pool);

#ifdef __cplusplus
}
#endif

#endif