Tue, 09 Sep 2025 20:56:47 +0200
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 | |
| 886 | 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 { |
| 886 | 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. */ | |
| 886 | 108 | void **data; |
| 775 | 109 | |
| 110 | /** Number of pooled memory items. */ | |
| 111 | size_t size; | |
| 112 | ||
| 113 | /** Memory pool capacity. */ | |
| 114 | size_t capacity; | |
| 886 | 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 | */ | |
|
854
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
159 | cx_attr_export |
| 852 | 160 | void cxMempoolFree(CxMempool *pool); |
| 161 | ||
| 162 | /** | |
| 886 | 163 | * Creates an array-based memory pool. |
| 775 | 164 | * |
| 886 | 165 | * The type determines how much additional memory is allocated per block |
| 166 | * to register a destructor function. | |
| 775 | 167 | * |
| 886 | 168 | * @param capacity the initial capacity of the pool (an implementation default if zero) |
| 169 | * @param type the type of memory pool | |
| 852 | 170 | * @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
|
171 | */ |
| 852 | 172 | cx_attr_nodiscard |
| 173 | cx_attr_malloc | |
| 174 | cx_attr_dealloc(cxMempoolFree, 1) | |
|
854
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
175 | cx_attr_export |
| 886 | 176 | CxMempool *cxMempoolCreate(size_t capacity, enum cx_mempool_type type); |
| 177 | ||
| 178 | /** | |
| 179 | * Creates a basic array-based memory pool. | |
| 180 | * | |
| 181 | * Convenience macro to create a memory pool of type #CX_MEMPOOL_TYPE_SIMPLE. | |
| 182 | * | |
| 183 | * @param capacity (@c size_t) the initial capacity of the pool | |
| 184 | * @return (@c CxMempool*) the created memory pool or @c NULL if allocation failed | |
| 185 | */ | |
| 186 | #define cxMempoolCreateSimple(capacity) cxMempoolCreate(capacity, CX_MEMPOOL_TYPE_SIMPLE) | |
| 187 | ||
| 188 | /** | |
| 189 | * Creates a basic array-based memory pool. | |
| 190 | * | |
| 191 | * Convenience macro to create a memory pool of type #CX_MEMPOOL_TYPE_ADVANCED. | |
| 192 | * | |
| 193 | * @param capacity (@c size_t) the initial capacity of the pool | |
| 194 | * @return (@c CxMempool*) the created memory pool or @c NULL if allocation failed | |
| 195 | */ | |
| 196 | #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
|
197 | |
| 775 | 198 | /** |
| 199 | * Creates a basic array-based memory pool. | |
| 200 | * | |
| 886 | 201 | * Convenience macro to create a memory pool of type #CX_MEMPOOL_TYPE_PURE. |
| 202 | * | |
| 852 | 203 | * @param capacity (@c size_t) the initial capacity of the pool |
| 204 | * @return (@c CxMempool*) the created memory pool or @c NULL if allocation failed | |
| 775 | 205 | */ |
| 886 | 206 | #define cxMempoolCreatePure(capacity) cxMempoolCreate(capacity, CX_MEMPOOL_TYPE_PURE) |
| 207 | ||
| 208 | /** | |
| 209 | * Sets the global destructor for all memory blocks within the specified pool. | |
| 210 | * | |
| 211 | * @param pool the memory pool | |
| 212 | * @param fnc the destructor that shall be applied to all memory blocks | |
| 213 | */ | |
| 214 | cx_attr_nonnull_arg(1) | |
| 215 | cx_attr_export | |
| 216 | void cxMempoolGlobalDestructor(CxMempool *pool, cx_destructor_func fnc); | |
| 217 | ||
| 218 | /** | |
| 219 | * Sets the global destructor for all memory blocks within the specified pool. | |
| 220 | * | |
| 221 | * @param pool the memory pool | |
| 222 | * @param fnc the destructor that shall be applied to all memory blocks | |
| 223 | * @param data additional data for the destructor function | |
| 224 | */ | |
| 225 | cx_attr_nonnull_arg(1) | |
| 226 | cx_attr_export | |
| 227 | 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
|
228 | |
|
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 | * 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
|
231 | * |
| 886 | 232 | * If the type of memory pool is not #CX_MEMPOOL_TYPE_SIMPLE, the behavior is undefined. |
| 775 | 233 | * If the memory is not managed by a UCX memory pool, the behavior is undefined. |
| 234 | * 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
|
235 | * |
| 775 | 236 | * @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
|
237 | * @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
|
238 | */ |
| 852 | 239 | cx_attr_nonnull |
|
854
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
240 | cx_attr_export |
| 775 | 241 | void cxMempoolSetDestructor( |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
242 | void *memory, |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
243 | cx_destructor_func fnc |
| 775 | 244 | ); |
| 245 | ||
| 246 | /** | |
| 886 | 247 | * Sets the destructor function for a specific allocated memory object. |
| 248 | * | |
| 249 | * If the type of memory pool is not #CX_MEMPOOL_TYPE_ADVANCED, the behavior is undefined. | |
| 250 | * If the memory is not managed by a UCX memory pool, the behavior is undefined. | |
| 251 | * The destructor MUST NOT free the memory. | |
| 252 | * | |
| 253 | * @param memory the object allocated in the pool | |
| 254 | * @param fnc the destructor function | |
| 255 | * @param data additional data for the destructor function | |
| 256 | */ | |
| 257 | cx_attr_nonnull | |
| 258 | cx_attr_export | |
| 259 | void cxMempoolSetDestructor2( | |
| 260 | void *memory, | |
| 261 | cx_destructor_func2 fnc, | |
| 262 | void *data | |
| 263 | ); | |
| 264 | ||
| 265 | /** | |
| 852 | 266 | * Removes the destructor function for a specific allocated memory object. |
| 267 | * | |
| 886 | 268 | * If the type of memory pool is not #CX_MEMPOOL_TYPE_SIMPLE, the behavior is undefined. |
| 852 | 269 | * If the memory is not managed by a UCX memory pool, the behavior is undefined. |
| 270 | * | |
| 271 | * @param memory the object allocated in the pool | |
| 272 | */ | |
| 273 | cx_attr_nonnull | |
|
854
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
274 | cx_attr_export |
| 852 | 275 | void cxMempoolRemoveDestructor(void *memory); |
| 276 | ||
| 277 | /** | |
| 886 | 278 | * Removes the destructor function for a specific allocated memory object. |
| 279 | * | |
| 280 | * If the type of memory pool is not #CX_MEMPOOL_TYPE_ADVANCED, the behavior is undefined. | |
| 281 | * If the memory is not managed by a UCX memory pool, the behavior is undefined. | |
| 282 | * | |
| 283 | * @param memory the object allocated in the pool | |
| 284 | */ | |
| 285 | cx_attr_nonnull | |
| 286 | cx_attr_export | |
| 287 | void cxMempoolRemoveDestructor2(void *memory); | |
| 288 | ||
| 289 | /** | |
| 775 | 290 | * Registers foreign memory with this pool. |
| 291 | * | |
| 292 | * The destructor, in contrast to memory allocated by the pool, MUST free the memory. | |
| 886 | 293 | * This function can be used with any pool of any type, since destructors for registered memory |
| 294 | * are entirely independent of the pool's memory management. | |
| 775 | 295 | * |
| 886 | 296 | * The destructor for the registered memory will be called after all pooled items have been freed. |
| 775 | 297 | * |
| 298 | * @param pool the pool | |
| 852 | 299 | * @param memory the object to register (MUST NOT be already allocated in the pool) |
| 775 | 300 | * @param destr the destructor function |
| 852 | 301 | * @retval zero success |
| 302 | * @retval non-zero failure | |
| 775 | 303 | */ |
| 852 | 304 | cx_attr_nonnull |
|
854
1c8401ece69e
update ucx to version 3.1
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
852
diff
changeset
|
305 | cx_attr_export |
| 775 | 306 | int cxMempoolRegister( |
| 307 | CxMempool *pool, | |
| 308 | void *memory, | |
| 309 | cx_destructor_func destr | |
| 310 | ); | |
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
311 | |
| 886 | 312 | |
| 313 | /** | |
| 314 | * Registers foreign memory with this pool. | |
| 315 | * | |
| 316 | * The destructor, in contrast to memory allocated by the pool, MUST free the memory. | |
| 317 | * This function can be used with any pool of any type, since destructors for registered memory | |
| 318 | * are entirely independent of the pool's memory management. | |
| 319 | * | |
| 320 | * The destructor for the registered memory will be called after all pooled items have been freed. | |
| 321 | * | |
| 322 | * @attention The data pointer MUST NOT be @c NULL. | |
| 323 | * If you wish to register a destructor without additional data, use cxMempoolRegister(). | |
| 324 | * | |
| 325 | * @param pool the pool | |
| 326 | * @param memory the object to register (MUST NOT be already allocated in the pool) | |
| 327 | * @param destr the destructor function | |
| 328 | * @param data additional data for the destructor function | |
| 329 | * @retval zero success | |
| 330 | * @retval non-zero failure | |
| 331 | */ | |
| 332 | cx_attr_nonnull | |
| 333 | cx_attr_export | |
| 334 | int cxMempoolRegister2( | |
| 335 | CxMempool *pool, | |
| 336 | void *memory, | |
| 337 | cx_destructor_func2 destr, | |
| 338 | void *data | |
| 339 | ); | |
| 340 | ||
| 341 | /** | |
| 342 | * Transfers all the memory managed by one pool to another. | |
| 343 | * | |
| 344 | * The allocator of the source pool will also be transferred and registered with the destination pool | |
| 345 | * and stays valid, as long as the destination pool is not destroyed. | |
| 346 | * | |
| 347 | * The source pool will get a completely new allocator and can be reused or destroyed afterward. | |
| 348 | * | |
| 349 | * This function fails when the destination pool has a different type than the source pool. | |
| 350 | * | |
| 351 | * @param source the pool to move the memory from | |
| 352 | * @param dest the pool where to transfer the memory to | |
| 353 | * @retval zero success | |
| 354 | * @retval non-zero allocation failure or incompatible pools | |
| 355 | */ | |
| 356 | cx_attr_nonnull | |
| 357 | cx_attr_export | |
| 358 | int cxMempoolTransfer( | |
| 359 | CxMempool *source, | |
| 360 | CxMempool *dest | |
| 361 | ); | |
| 362 | ||
| 363 | /** | |
| 364 | * Transfers an object from one pool to another. | |
| 365 | * | |
| 366 | * This function fails when the destination pool has a different type than the source pool. | |
| 367 | * | |
| 368 | * @attention If the object maintains a reference to the pool's allocator, | |
| 369 | * you must make sure to update that reference to the allocator of the destination pool. | |
| 370 | * | |
| 371 | * @param source the pool to move the memory from | |
| 372 | * @param dest the pool where to transfer the memory to | |
| 373 | * @param obj pointer to the object that shall be transferred | |
| 374 | * @retval zero success | |
| 375 | * @retval non-zero failure, or the object was not found in the source pool, or the pools are incompatible | |
| 376 | */ | |
| 377 | cx_attr_nonnull | |
| 378 | cx_attr_export | |
| 379 | int cxMempoolTransferObject( | |
| 380 | CxMempool *source, | |
| 381 | CxMempool *dest, | |
| 382 | const void *obj | |
| 383 | ); | |
| 384 | ||
|
747
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
385 | #ifdef __cplusplus |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
386 | } // extern "C" |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
387 | #endif |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
388 | |
|
efbd59642577
ucx 3 update, basic dav commands work, most stuff is still broken
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
389 | #endif // UCX_MEMPOOL_H |