Wed, 31 Dec 2025 16:41:16 +0100
update ucx to version 4.0
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1 | /* |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
3 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
4 | * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
5 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
8 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
11 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
15 | * |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
27 | */ |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
28 | /** |
| 852 | 29 | * @file mempool.h |
| 30 | * @brief Interface for memory pool implementations. | |
| 31 | * @author Mike Becker | |
| 32 | * @author Olaf Wintermann | |
| 33 | * @copyright 2-Clause BSD License | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
34 | */ |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
35 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
36 | #ifndef UCX_MEMPOOL_H |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
37 | #define UCX_MEMPOOL_H |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
38 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
39 | #include "common.h" |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
40 | #include "allocator.h" |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
41 | |
| 886 | 42 | /** A memory block in a simple memory pool. */ |
| 43 | struct cx_mempool_memory_s { | |
| 44 | /** The destructor. */ | |
| 45 | cx_destructor_func destructor; | |
| 46 | /** The actual memory. */ | |
| 47 | char c[]; | |
| 48 | }; | |
| 49 | ||
| 50 | /** A memory block in an advanced memory pool. */ | |
| 51 | struct cx_mempool_memory2_s { | |
| 52 | /** The destructor. */ | |
| 53 | cx_destructor_func2 destructor; | |
| 54 | /** Data for the destructor. */ | |
| 55 | void *data; | |
| 56 | /** The actual memory. */ | |
| 57 | char c[]; | |
| 58 | }; | |
| 59 | ||
| 60 | /** Represents memory that is not allocated by, but registered with a pool. */ | |
| 61 | struct cx_mempool_foreign_memory_s { | |
| 62 | /** The foreign memory. */ | |
| 63 | void* mem; | |
| 64 | union { | |
| 65 | /** Simple destructor. */ | |
| 66 | cx_destructor_func destr; | |
| 67 | /** Advanced destructor. */ | |
| 68 | cx_destructor_func2 destr2; | |
| 69 | }; | |
| 70 | /** Data for the advanced destructor. */ | |
| 71 | void *destr2_data; | |
| 72 | }; | |
| 73 | ||
| 74 | /** Specifies how individual blocks are allocated. */ | |
| 75 | enum cx_mempool_type { | |
| 76 | /** | |
| 77 | * Allows registration of cx_destructor_func for each memory block. | |
| 78 | */ | |
| 79 | CX_MEMPOOL_TYPE_SIMPLE, | |
| 80 | /** | |
| 81 | * Allows registration of cx_destructor_func2 for each memory block. | |
| 82 | */ | |
| 83 | CX_MEMPOOL_TYPE_ADVANCED, | |
| 84 | /** | |
| 85 | * No individual destructor registration allowed. | |
| 86 | * | |
| 87 | * In this mode, no additional memory per block is allocated. | |
| 88 | */ | |
| 89 | CX_MEMPOOL_TYPE_PURE, | |
| 90 | }; | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
91 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
92 | /** |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
93 | * The basic structure of a memory pool. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
94 | * Should be the first member of an actual memory pool implementation. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
95 | */ |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
96 | struct cx_mempool_s { |
| 886 | 97 | /** The used allocator, initialized with the cxDefaultAllocator. */ |
| 98 | const CxAllocator * const base_allocator; | |
| 99 | ||
| 775 | 100 | /** The provided allocator. */ |
| 852 | 101 | const CxAllocator *allocator; |
| 775 | 102 | |
| 103 | /** Array of pooled memory. */ | |
| 886 | 104 | void **data; |
| 775 | 105 | |
| 106 | /** Number of pooled memory items. */ | |
| 107 | size_t size; | |
| 108 | ||
| 109 | /** Memory pool capacity. */ | |
| 110 | size_t capacity; | |
| 886 | 111 | |
| 112 | /** Array of registered memory. */ | |
| 113 | struct cx_mempool_foreign_memory_s *registered; | |
| 114 | ||
| 115 | /** Number of registered memory items. */ | |
| 116 | size_t registered_size; | |
| 117 | ||
| 118 | /** Capacity for registered memory. */ | |
| 119 | size_t registered_capacity; | |
| 120 | ||
| 121 | /** | |
| 122 | * A destructor that shall be called before deallocating a memory block. | |
| 123 | * This destructor MUST NOT free the memory itself. | |
| 124 | * | |
| 125 | * It is guaranteed that this destructor is called after the individual | |
| 126 | * destructor of the memory block and before @c destr2. | |
| 127 | */ | |
| 128 | cx_destructor_func destr; | |
| 129 | ||
| 130 | /** | |
| 131 | * A destructor that shall be called before deallocating a memory block. | |
| 132 | * This destructor MUST NOT free the memory itself. | |
| 133 | * | |
| 134 | * It is guaranteed that this destructor is called after the individual | |
| 135 | * destructor of the memory block and @c destr. | |
| 136 | */ | |
| 137 | cx_destructor_func2 destr2; | |
| 138 | ||
| 139 | /** | |
| 140 | * Additional data for the @c destr2. | |
| 141 | */ | |
| 142 | void *destr2_data; | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
143 | }; |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
144 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
145 | /** |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
146 | * Common type for all memory pool implementations. |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
147 | */ |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
148 | typedef struct cx_mempool_s CxMempool; |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
149 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
150 | /** |
| 852 | 151 | * Deallocates a memory pool and frees the managed memory. |
| 152 | * | |
| 153 | * @param pool the memory pool to free | |
| 154 | */ | |
|
894
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
889
diff
changeset
|
155 | CX_EXTERN |
|
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
889
diff
changeset
|
156 | void cxMempoolFree(CxMempool *pool); |
| 852 | 157 | |
| 158 | /** | |
| 886 | 159 | * Creates an array-based memory pool. |
| 775 | 160 | * |
| 886 | 161 | * The type determines how much additional memory is allocated per block |
| 162 | * to register a destructor function. | |
| 775 | 163 | * |
| 886 | 164 | * @param capacity the initial capacity of the pool (an implementation default if zero) |
| 165 | * @param type the type of memory pool | |
| 852 | 166 | * @return the created memory pool or @c NULL if allocation failed |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
167 | */ |
|
894
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
889
diff
changeset
|
168 | CX_EXTERN CX_NODISCARD CX_MALLOC CX_DEALLOC(cxMempoolFree, 1) |
|
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
889
diff
changeset
|
169 | CxMempool *cxMempoolCreate(size_t capacity, enum cx_mempool_type type); |
| 886 | 170 | |
| 171 | /** | |
| 172 | * Creates a basic array-based memory pool. | |
| 173 | * | |
| 174 | * Convenience macro to create a memory pool of type #CX_MEMPOOL_TYPE_SIMPLE. | |
| 175 | * | |
| 176 | * @param capacity (@c size_t) the initial capacity of the pool | |
| 177 | * @return (@c CxMempool*) the created memory pool or @c NULL if allocation failed | |
| 178 | */ | |
| 179 | #define cxMempoolCreateSimple(capacity) cxMempoolCreate(capacity, CX_MEMPOOL_TYPE_SIMPLE) | |
| 180 | ||
| 181 | /** | |
| 182 | * Creates a basic array-based memory pool. | |
| 183 | * | |
| 184 | * Convenience macro to create a memory pool of type #CX_MEMPOOL_TYPE_ADVANCED. | |
| 185 | * | |
| 186 | * @param capacity (@c size_t) the initial capacity of the pool | |
| 187 | * @return (@c CxMempool*) the created memory pool or @c NULL if allocation failed | |
| 188 | */ | |
| 189 | #define cxMempoolCreateAdvanced(capacity) cxMempoolCreate(capacity, CX_MEMPOOL_TYPE_ADVANCED) | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
190 | |
| 775 | 191 | /** |
| 192 | * Creates a basic array-based memory pool. | |
| 193 | * | |
| 886 | 194 | * Convenience macro to create a memory pool of type #CX_MEMPOOL_TYPE_PURE. |
| 195 | * | |
| 852 | 196 | * @param capacity (@c size_t) the initial capacity of the pool |
| 197 | * @return (@c CxMempool*) the created memory pool or @c NULL if allocation failed | |
| 775 | 198 | */ |
| 886 | 199 | #define cxMempoolCreatePure(capacity) cxMempoolCreate(capacity, CX_MEMPOOL_TYPE_PURE) |
| 200 | ||
| 201 | /** | |
| 202 | * Sets the global destructor for all memory blocks within the specified pool. | |
| 203 | * | |
| 204 | * @param pool the memory pool | |
| 205 | * @param fnc the destructor that shall be applied to all memory blocks | |
| 206 | */ | |
|
894
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
889
diff
changeset
|
207 | CX_EXTERN CX_NONNULL_ARG(1) |
|
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
889
diff
changeset
|
208 | void cxMempoolGlobalDestructor(CxMempool *pool, cx_destructor_func fnc); |
| 886 | 209 | |
| 210 | /** | |
| 211 | * Sets the global destructor for all memory blocks within the specified pool. | |
| 212 | * | |
| 213 | * @param pool the memory pool | |
| 214 | * @param fnc the destructor that shall be applied to all memory blocks | |
| 215 | * @param data additional data for the destructor function | |
| 216 | */ | |
|
894
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
889
diff
changeset
|
217 | CX_EXTERN CX_NONNULL_ARG(1) |
|
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
889
diff
changeset
|
218 | void cxMempoolGlobalDestructor2(CxMempool *pool, cx_destructor_func2 fnc, void *data); |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
219 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
220 | /** |
| 775 | 221 | * Sets the destructor function for a specific allocated memory object. |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
222 | * |
| 886 | 223 | * If the type of memory pool is not #CX_MEMPOOL_TYPE_SIMPLE, the behavior is undefined. |
| 775 | 224 | * If the memory is not managed by a UCX memory pool, the behavior is undefined. |
| 225 | * The destructor MUST NOT free the memory. | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
226 | * |
| 775 | 227 | * @param memory the object allocated in the pool |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
228 | * @param fnc the destructor function |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
229 | */ |
|
894
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
889
diff
changeset
|
230 | CX_EXTERN CX_NONNULL |
|
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
889
diff
changeset
|
231 | void cxMempoolSetDestructor(void *memory, cx_destructor_func fnc); |
| 775 | 232 | |
| 233 | /** | |
| 886 | 234 | * Sets the destructor function for a specific allocated memory object. |
| 235 | * | |
| 236 | * If the type of memory pool is not #CX_MEMPOOL_TYPE_ADVANCED, the behavior is undefined. | |
| 237 | * If the memory is not managed by a UCX memory pool, the behavior is undefined. | |
| 238 | * The destructor MUST NOT free the memory. | |
| 239 | * | |
| 240 | * @param memory the object allocated in the pool | |
| 241 | * @param fnc the destructor function | |
| 242 | * @param data additional data for the destructor function | |
| 243 | */ | |
|
894
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
889
diff
changeset
|
244 | CX_EXTERN CX_NONNULL |
|
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
889
diff
changeset
|
245 | void cxMempoolSetDestructor2(void *memory, cx_destructor_func2 fnc, void *data); |
| 886 | 246 | |
| 247 | /** | |
| 852 | 248 | * Removes the destructor function for a specific allocated memory object. |
| 249 | * | |
| 886 | 250 | * If the type of memory pool is not #CX_MEMPOOL_TYPE_SIMPLE, the behavior is undefined. |
| 852 | 251 | * If the memory is not managed by a UCX memory pool, the behavior is undefined. |
| 252 | * | |
| 253 | * @param memory the object allocated in the pool | |
| 254 | */ | |
|
894
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
889
diff
changeset
|
255 | CX_EXTERN CX_NONNULL |
|
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
889
diff
changeset
|
256 | void cxMempoolRemoveDestructor(void *memory); |
| 852 | 257 | |
| 258 | /** | |
| 886 | 259 | * Removes the destructor function for a specific allocated memory object. |
| 260 | * | |
| 261 | * If the type of memory pool is not #CX_MEMPOOL_TYPE_ADVANCED, the behavior is undefined. | |
| 262 | * If the memory is not managed by a UCX memory pool, the behavior is undefined. | |
| 263 | * | |
| 264 | * @param memory the object allocated in the pool | |
| 265 | */ | |
|
894
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
889
diff
changeset
|
266 | CX_EXTERN CX_NONNULL |
|
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
889
diff
changeset
|
267 | void cxMempoolRemoveDestructor2(void *memory); |
| 886 | 268 | |
| 269 | /** | |
| 775 | 270 | * Registers foreign memory with this pool. |
| 271 | * | |
| 272 | * The destructor, in contrast to memory allocated by the pool, MUST free the memory. | |
| 886 | 273 | * This function can be used with any pool of any type, since destructors for registered memory |
| 274 | * are entirely independent of the pool's memory management. | |
| 775 | 275 | * |
| 886 | 276 | * The destructor for the registered memory will be called after all pooled items have been freed. |
| 775 | 277 | * |
| 278 | * @param pool the pool | |
| 852 | 279 | * @param memory the object to register (MUST NOT be already allocated in the pool) |
| 775 | 280 | * @param destr the destructor function |
| 852 | 281 | * @retval zero success |
| 282 | * @retval non-zero failure | |
| 775 | 283 | */ |
|
894
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
889
diff
changeset
|
284 | CX_EXTERN CX_NONNULL |
|
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
889
diff
changeset
|
285 | int cxMempoolRegister(CxMempool *pool, void *memory, cx_destructor_func destr); |
| 886 | 286 | |
| 287 | /** | |
| 288 | * Registers foreign memory with this pool. | |
| 289 | * | |
| 290 | * The destructor, in contrast to memory allocated by the pool, MUST free the memory. | |
| 291 | * This function can be used with any pool of any type, since destructors for registered memory | |
| 292 | * are entirely independent of the pool's memory management. | |
| 293 | * | |
| 294 | * The destructor for the registered memory will be called after all pooled items have been freed. | |
| 295 | * | |
| 296 | * @attention The data pointer MUST NOT be @c NULL. | |
| 297 | * If you wish to register a destructor without additional data, use cxMempoolRegister(). | |
| 298 | * | |
| 299 | * @param pool the pool | |
| 300 | * @param memory the object to register (MUST NOT be already allocated in the pool) | |
| 301 | * @param destr the destructor function | |
| 302 | * @param data additional data for the destructor function | |
| 303 | * @retval zero success | |
| 304 | * @retval non-zero failure | |
| 305 | */ | |
|
894
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
889
diff
changeset
|
306 | CX_EXTERN CX_NONNULL |
|
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
889
diff
changeset
|
307 | int cxMempoolRegister2(CxMempool *pool, void *memory, cx_destructor_func2 destr, void *data); |
| 886 | 308 | |
| 309 | /** | |
| 310 | * Transfers all the memory managed by one pool to another. | |
| 311 | * | |
| 312 | * The allocator of the source pool will also be transferred and registered with the destination pool | |
| 313 | * and stays valid, as long as the destination pool is not destroyed. | |
| 314 | * | |
| 315 | * The source pool will get a completely new allocator and can be reused or destroyed afterward. | |
| 316 | * | |
| 317 | * This function fails when the destination pool has a different type than the source pool. | |
| 318 | * | |
| 319 | * @param source the pool to move the memory from | |
| 320 | * @param dest the pool where to transfer the memory to | |
| 321 | * @retval zero success | |
| 322 | * @retval non-zero allocation failure or incompatible pools | |
| 323 | */ | |
|
894
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
889
diff
changeset
|
324 | CX_EXTERN CX_NONNULL |
|
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
889
diff
changeset
|
325 | int cxMempoolTransfer(CxMempool *source, CxMempool *dest); |
| 886 | 326 | |
| 327 | /** | |
| 328 | * Transfers an object from one pool to another. | |
| 329 | * | |
| 330 | * This function fails when the destination pool has a different type than the source pool. | |
| 331 | * | |
| 332 | * @attention If the object maintains a reference to the pool's allocator, | |
| 333 | * you must make sure to update that reference to the allocator of the destination pool. | |
| 334 | * | |
| 335 | * @param source the pool to move the memory from | |
| 336 | * @param dest the pool where to transfer the memory to | |
| 337 | * @param obj pointer to the object that shall be transferred | |
| 338 | * @retval zero success | |
| 339 | * @retval non-zero failure, or the object was not found in the source pool, or the pools are incompatible | |
| 340 | */ | |
|
894
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
889
diff
changeset
|
341 | CX_EXTERN CX_NONNULL |
|
e86049631677
update ucx to version 4.0
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
889
diff
changeset
|
342 | int cxMempoolTransferObject(CxMempool *source, CxMempool *dest, const void *obj); |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
343 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
344 | #endif // UCX_MEMPOOL_H |