Sat, 08 Nov 2025 23:06:11 +0100
update ucx
|
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 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
42 | #ifdef __cplusplus |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
43 | extern "C" { |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
44 | #endif |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
45 | |
| 888 | 46 | /** A memory block in a simple memory pool. */ |
| 47 | struct cx_mempool_memory_s { | |
| 48 | /** The destructor. */ | |
| 49 | cx_destructor_func destructor; | |
| 50 | /** The actual memory. */ | |
| 51 | char c[]; | |
| 52 | }; | |
| 53 | ||
| 54 | /** A memory block in an advanced memory pool. */ | |
| 55 | struct cx_mempool_memory2_s { | |
| 56 | /** The destructor. */ | |
| 57 | cx_destructor_func2 destructor; | |
| 58 | /** Data for the destructor. */ | |
| 59 | void *data; | |
| 60 | /** The actual memory. */ | |
| 61 | char c[]; | |
| 62 | }; | |
| 63 | ||
| 64 | /** Represents memory that is not allocated by, but registered with a pool. */ | |
| 65 | struct cx_mempool_foreign_memory_s { | |
| 66 | /** The foreign memory. */ | |
| 67 | void* mem; | |
| 68 | union { | |
| 69 | /** Simple destructor. */ | |
| 70 | cx_destructor_func destr; | |
| 71 | /** Advanced destructor. */ | |
| 72 | cx_destructor_func2 destr2; | |
| 73 | }; | |
| 74 | /** Data for the advanced destructor. */ | |
| 75 | void *destr2_data; | |
| 76 | }; | |
| 77 | ||
| 78 | /** Specifies how individual blocks are allocated. */ | |
| 79 | enum cx_mempool_type { | |
| 80 | /** | |
| 81 | * Allows registration of cx_destructor_func for each memory block. | |
| 82 | */ | |
| 83 | CX_MEMPOOL_TYPE_SIMPLE, | |
| 84 | /** | |
| 85 | * Allows registration of cx_destructor_func2 for each memory block. | |
| 86 | */ | |
| 87 | CX_MEMPOOL_TYPE_ADVANCED, | |
| 88 | /** | |
| 89 | * No individual destructor registration allowed. | |
| 90 | * | |
| 91 | * In this mode, no additional memory per block is allocated. | |
| 92 | */ | |
| 93 | CX_MEMPOOL_TYPE_PURE, | |
| 94 | }; | |
|
747
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 | /** |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
97 | * 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
|
98 | * 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
|
99 | */ |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
100 | struct cx_mempool_s { |
| 888 | 101 | /** The used allocator, initialized with the cxDefaultAllocator. */ |
| 102 | const CxAllocator * const base_allocator; | |
| 103 | ||
| 775 | 104 | /** The provided allocator. */ |
| 852 | 105 | const CxAllocator *allocator; |
| 775 | 106 | |
| 107 | /** Array of pooled memory. */ | |
| 888 | 108 | void **data; |
| 775 | 109 | |
| 110 | /** Number of pooled memory items. */ | |
| 111 | size_t size; | |
| 112 | ||
| 113 | /** Memory pool capacity. */ | |
| 114 | size_t capacity; | |
| 888 | 115 | |
| 116 | /** Array of registered memory. */ | |
| 117 | struct cx_mempool_foreign_memory_s *registered; | |
| 118 | ||
| 119 | /** Number of registered memory items. */ | |
| 120 | size_t registered_size; | |
| 121 | ||
| 122 | /** Capacity for registered memory. */ | |
| 123 | size_t registered_capacity; | |
| 124 | ||
| 125 | /** | |
| 126 | * A destructor that shall be called before deallocating a memory block. | |
| 127 | * This destructor MUST NOT free the memory itself. | |
| 128 | * | |
| 129 | * It is guaranteed that this destructor is called after the individual | |
| 130 | * destructor of the memory block and before @c destr2. | |
| 131 | */ | |
| 132 | cx_destructor_func destr; | |
| 133 | ||
| 134 | /** | |
| 135 | * A destructor that shall be called before deallocating a memory block. | |
| 136 | * This destructor MUST NOT free the memory itself. | |
| 137 | * | |
| 138 | * It is guaranteed that this destructor is called after the individual | |
| 139 | * destructor of the memory block and @c destr. | |
| 140 | */ | |
| 141 | cx_destructor_func2 destr2; | |
| 142 | ||
| 143 | /** | |
| 144 | * Additional data for the @c destr2. | |
| 145 | */ | |
| 146 | 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
|
147 | }; |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
148 | |
|
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 | * 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
|
151 | */ |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
152 | 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
|
153 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
154 | /** |
| 852 | 155 | * Deallocates a memory pool and frees the managed memory. |
| 156 | * | |
| 157 | * @param pool the memory pool to free | |
| 158 | */ | |
| 888 | 159 | CX_EXPORT void cxMempoolFree(CxMempool *pool); |
| 852 | 160 | |
| 161 | /** | |
| 888 | 162 | * Creates an array-based memory pool. |
| 775 | 163 | * |
| 888 | 164 | * The type determines how much additional memory is allocated per block |
| 165 | * to register a destructor function. | |
| 775 | 166 | * |
| 888 | 167 | * @param capacity the initial capacity of the pool (an implementation default if zero) |
| 168 | * @param type the type of memory pool | |
| 852 | 169 | * @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
|
170 | */ |
| 888 | 171 | cx_attr_nodiscard cx_attr_malloc cx_attr_dealloc(cxMempoolFree, 1) |
| 172 | CX_EXPORT CxMempool *cxMempoolCreate(size_t capacity, enum cx_mempool_type type); | |
| 173 | ||
| 174 | /** | |
| 175 | * Creates a basic array-based memory pool. | |
| 176 | * | |
| 177 | * Convenience macro to create a memory pool of type #CX_MEMPOOL_TYPE_SIMPLE. | |
| 178 | * | |
| 179 | * @param capacity (@c size_t) the initial capacity of the pool | |
| 180 | * @return (@c CxMempool*) the created memory pool or @c NULL if allocation failed | |
| 181 | */ | |
| 182 | #define cxMempoolCreateSimple(capacity) cxMempoolCreate(capacity, CX_MEMPOOL_TYPE_SIMPLE) | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
183 | |
| 775 | 184 | /** |
| 185 | * Creates a basic array-based memory pool. | |
| 186 | * | |
| 888 | 187 | * Convenience macro to create a memory pool of type #CX_MEMPOOL_TYPE_ADVANCED. |
| 188 | * | |
| 189 | * @param capacity (@c size_t) the initial capacity of the pool | |
| 190 | * @return (@c CxMempool*) the created memory pool or @c NULL if allocation failed | |
| 191 | */ | |
| 192 | #define cxMempoolCreateAdvanced(capacity) cxMempoolCreate(capacity, CX_MEMPOOL_TYPE_ADVANCED) | |
| 193 | ||
| 194 | /** | |
| 195 | * Creates a basic array-based memory pool. | |
| 196 | * | |
| 197 | * Convenience macro to create a memory pool of type #CX_MEMPOOL_TYPE_PURE. | |
| 198 | * | |
| 852 | 199 | * @param capacity (@c size_t) the initial capacity of the pool |
| 200 | * @return (@c CxMempool*) the created memory pool or @c NULL if allocation failed | |
| 775 | 201 | */ |
| 888 | 202 | #define cxMempoolCreatePure(capacity) cxMempoolCreate(capacity, CX_MEMPOOL_TYPE_PURE) |
| 203 | ||
| 204 | /** | |
| 205 | * Sets the global destructor for all memory blocks within the specified pool. | |
| 206 | * | |
| 207 | * @param pool the memory pool | |
| 208 | * @param fnc the destructor that shall be applied to all memory blocks | |
| 209 | */ | |
| 210 | cx_attr_nonnull_arg(1) | |
| 211 | CX_EXPORT void cxMempoolGlobalDestructor(CxMempool *pool, cx_destructor_func fnc); | |
| 212 | ||
| 213 | /** | |
| 214 | * Sets the global destructor for all memory blocks within the specified pool. | |
| 215 | * | |
| 216 | * @param pool the memory pool | |
| 217 | * @param fnc the destructor that shall be applied to all memory blocks | |
| 218 | * @param data additional data for the destructor function | |
| 219 | */ | |
| 220 | cx_attr_nonnull_arg(1) | |
| 221 | CX_EXPORT 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
|
222 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
223 | /** |
| 775 | 224 | * 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
|
225 | * |
| 888 | 226 | * If the type of memory pool is not #CX_MEMPOOL_TYPE_SIMPLE, the behavior is undefined. |
| 775 | 227 | * If the memory is not managed by a UCX memory pool, the behavior is undefined. |
| 228 | * 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
|
229 | * |
| 775 | 230 | * @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
|
231 | * @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
|
232 | */ |
| 852 | 233 | cx_attr_nonnull |
| 888 | 234 | CX_EXPORT void cxMempoolSetDestructor(void *memory, cx_destructor_func fnc); |
| 235 | ||
| 236 | /** | |
| 237 | * Sets the destructor function for a specific allocated memory object. | |
| 238 | * | |
| 239 | * If the type of memory pool is not #CX_MEMPOOL_TYPE_ADVANCED, the behavior is undefined. | |
| 240 | * If the memory is not managed by a UCX memory pool, the behavior is undefined. | |
| 241 | * The destructor MUST NOT free the memory. | |
| 242 | * | |
| 243 | * @param memory the object allocated in the pool | |
| 244 | * @param fnc the destructor function | |
| 245 | * @param data additional data for the destructor function | |
| 246 | */ | |
| 247 | cx_attr_nonnull | |
| 248 | CX_EXPORT void cxMempoolSetDestructor2(void *memory, cx_destructor_func2 fnc, void *data); | |
| 775 | 249 | |
| 250 | /** | |
| 852 | 251 | * Removes the destructor function for a specific allocated memory object. |
| 252 | * | |
| 888 | 253 | * If the type of memory pool is not #CX_MEMPOOL_TYPE_SIMPLE, the behavior is undefined. |
| 852 | 254 | * If the memory is not managed by a UCX memory pool, the behavior is undefined. |
| 255 | * | |
| 256 | * @param memory the object allocated in the pool | |
| 257 | */ | |
| 258 | cx_attr_nonnull | |
| 888 | 259 | CX_EXPORT void cxMempoolRemoveDestructor(void *memory); |
| 260 | ||
| 261 | /** | |
| 262 | * Removes the destructor function for a specific allocated memory object. | |
| 263 | * | |
| 264 | * If the type of memory pool is not #CX_MEMPOOL_TYPE_ADVANCED, the behavior is undefined. | |
| 265 | * If the memory is not managed by a UCX memory pool, the behavior is undefined. | |
| 266 | * | |
| 267 | * @param memory the object allocated in the pool | |
| 268 | */ | |
| 269 | cx_attr_nonnull | |
| 270 | CX_EXPORT void cxMempoolRemoveDestructor2(void *memory); | |
| 852 | 271 | |
| 272 | /** | |
| 775 | 273 | * Registers foreign memory with this pool. |
| 274 | * | |
| 275 | * The destructor, in contrast to memory allocated by the pool, MUST free the memory. | |
| 888 | 276 | * This function can be used with any pool of any type, since destructors for registered memory |
| 277 | * are entirely independent of the pool's memory management. | |
| 775 | 278 | * |
| 888 | 279 | * The destructor for the registered memory will be called after all pooled items have been freed. |
| 775 | 280 | * |
| 281 | * @param pool the pool | |
| 852 | 282 | * @param memory the object to register (MUST NOT be already allocated in the pool) |
| 775 | 283 | * @param destr the destructor function |
| 852 | 284 | * @retval zero success |
| 285 | * @retval non-zero failure | |
| 775 | 286 | */ |
| 852 | 287 | cx_attr_nonnull |
| 888 | 288 | CX_EXPORT int cxMempoolRegister(CxMempool *pool, void *memory, cx_destructor_func destr); |
| 289 | ||
| 290 | ||
| 291 | /** | |
| 292 | * Registers foreign memory with this pool. | |
| 293 | * | |
| 294 | * The destructor, in contrast to memory allocated by the pool, MUST free the memory. | |
| 295 | * This function can be used with any pool of any type, since destructors for registered memory | |
| 296 | * are entirely independent of the pool's memory management. | |
| 297 | * | |
| 298 | * The destructor for the registered memory will be called after all pooled items have been freed. | |
| 299 | * | |
| 300 | * @attention The data pointer MUST NOT be @c NULL. | |
| 301 | * If you wish to register a destructor without additional data, use cxMempoolRegister(). | |
| 302 | * | |
| 303 | * @param pool the pool | |
| 304 | * @param memory the object to register (MUST NOT be already allocated in the pool) | |
| 305 | * @param destr the destructor function | |
| 306 | * @param data additional data for the destructor function | |
| 307 | * @retval zero success | |
| 308 | * @retval non-zero failure | |
| 309 | */ | |
| 310 | cx_attr_nonnull | |
| 311 | CX_EXPORT int cxMempoolRegister2(CxMempool *pool, void *memory, cx_destructor_func2 destr, void *data); | |
| 312 | ||
| 313 | /** | |
| 314 | * Transfers all the memory managed by one pool to another. | |
| 315 | * | |
| 316 | * The allocator of the source pool will also be transferred and registered with the destination pool | |
| 317 | * and stays valid, as long as the destination pool is not destroyed. | |
| 318 | * | |
| 319 | * The source pool will get a completely new allocator and can be reused or destroyed afterward. | |
| 320 | * | |
| 321 | * This function fails when the destination pool has a different type than the source pool. | |
| 322 | * | |
| 323 | * @param source the pool to move the memory from | |
| 324 | * @param dest the pool where to transfer the memory to | |
| 325 | * @retval zero success | |
| 326 | * @retval non-zero allocation failure or incompatible pools | |
| 327 | */ | |
| 328 | cx_attr_nonnull | |
| 329 | CX_EXPORT int cxMempoolTransfer(CxMempool *source, CxMempool *dest); | |
| 330 | ||
| 331 | /** | |
| 332 | * Transfers an object from one pool to another. | |
| 333 | * | |
| 334 | * This function fails when the destination pool has a different type than the source pool. | |
| 335 | * | |
| 336 | * @attention If the object maintains a reference to the pool's allocator, | |
| 337 | * you must make sure to update that reference to the allocator of the destination pool. | |
| 338 | * | |
| 339 | * @param source the pool to move the memory from | |
| 340 | * @param dest the pool where to transfer the memory to | |
| 341 | * @param obj pointer to the object that shall be transferred | |
| 342 | * @retval zero success | |
| 343 | * @retval non-zero failure, or the object was not found in the source pool, or the pools are incompatible | |
| 344 | */ | |
| 345 | cx_attr_nonnull | |
| 346 | CX_EXPORT 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
|
347 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
348 | #ifdef __cplusplus |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
349 | } // extern "C" |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
350 | #endif |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
351 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
352 | #endif // UCX_MEMPOOL_H |