xref: /nrf52832-nimble/packages/NimBLE-latest/porting/nimble/include/mem/mem.h (revision 042d53a763ad75cb1465103098bb88c245d95138)
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements.  See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership.  The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License.  You may obtain a copy of the License at
9  *
10  *  http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied.  See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */
19 
20 #ifndef H_UTIL_MEM_
21 #define H_UTIL_MEM_
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 struct os_mempool;
28 struct os_mbuf_pool;
29 
30 int mem_malloc_mempool(struct os_mempool *mempool, uint16_t num_blocks,
31                        uint32_t block_size, char *name, void **out_buf);
32 int mem_malloc_mempool_ext(struct os_mempool_ext *mempool, uint16_t num_blocks,
33                            uint32_t block_size, char *name, void **out_buf);
34 
35 int mem_malloc_mbuf_pool(struct os_mempool *mempool,
36                          struct os_mbuf_pool *mbuf_pool, uint16_t num_blocks,
37                          uint32_t block_size, char *name,
38                          void **out_buf);
39 int mem_malloc_mbufpkt_pool(struct os_mempool *mempool,
40                             struct os_mbuf_pool *mbuf_pool, int num_blocks,
41                             int block_size, char *name,
42                             void **out_buf);
43 int mem_init_mbuf_pool(void *mem, struct os_mempool *mempool,
44                        struct os_mbuf_pool *mbuf_pool, int num_blocks,
45                        int block_size, char *name);
46 
47 /**
48  * Specifies a function used as a callback.  Functions of this type allocate an
49  * mbuf chain meant to hold a packet fragment.  The resulting mbuf must contain
50  * a pkthdr.
51  *
52  * @param frag_size             The number of data bytes that the mbuf will
53  *                                  eventually contain.
54  * @param arg                   A generic parameter.
55  *
56  * @return                      An allocated mbuf chain on success;
57  *                              NULL on failure.
58  */
59 typedef struct os_mbuf *mem_frag_alloc_fn(uint16_t frag_size, void *arg);
60 
61 struct os_mbuf *mem_split_frag(struct os_mbuf **om, uint16_t max_frag_sz,
62                                mem_frag_alloc_fn *alloc_cb, void *cb_arg);
63 
64 #ifdef __cplusplus
65 }
66 #endif
67 
68 #endif
69