ucx/mempool.h

Mon, 09 Oct 2017 14:55:47 +0200

author
Mike Becker <universe@uap-core.de>
date
Mon, 09 Oct 2017 14:55:47 +0200
changeset 329
2dc61cc5a8ac
parent 314
8722a668fb2a
permissions
-rw-r--r--

adds error message to dav, when an invalid date format is specified for the -u option

5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
1 /*
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
3 *
255
bf19378aed58 updates UCX to version 0.11
Mike Becker <universe@uap-core.de>
parents: 169
diff changeset
4 * Copyright 2016 Olaf Wintermann. All rights reserved.
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
5 *
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
6 * Redistribution and use in source and binary forms, with or without
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
7 * modification, are permitted provided that the following conditions are met:
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
8 *
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
10 * notice, this list of conditions and the following disclaimer.
1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
14 * documentation and/or other materials provided with the distribution.
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
15 *
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
29 /**
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
30 * @file mempool.h
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
31 *
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
32 * Memory pool implementation.
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
33 *
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
34 * @author Mike Becker
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
35 * @author Olaf Wintermann
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
36 */
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
37
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
38 #ifndef UCX_MEMPOOL_H
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
39 #define UCX_MEMPOOL_H
1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41 #include "ucx.h"
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 #include <stddef.h>
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 #include "allocator.h"
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45 #ifdef __cplusplus
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46 extern "C" {
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47 #endif
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
49 /**
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
50 * UCX mempool structure.
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
51 */
1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 typedef struct {
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
53 /** UcxAllocator based on this pool */
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
54 UcxAllocator *allocator;
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
55
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
56 /** List of pointers to pooled memory. */
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
57 void **data;
17
11dffb40cd91 new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
58
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
59 /** Count of pooled memory items. */
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
60 size_t ndata;
17
11dffb40cd91 new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
61
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
62 /** Memory pool size. */
40
a95ee94b9204 supports whitespace in paths
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
63 size_t size;
1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64 } UcxMempool;
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
66 /** Shorthand for a new default memory pool with a capacity of 16 elements. */
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
67 #define ucx_mempool_new_default() ucx_mempool_new(16)
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
68
1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
70 /**
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
71 * Creates a memory pool with the specified initial size.
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
72 *
314
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
73 * As the created memory pool automatically grows in size by factor two when
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
74 * trying to allocate memory on a full pool, it is recommended that you use
314
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
75 * a power of two for the initial size.
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
76 *
314
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
77 * @param n initial pool size (should be a power of two, e.g. 16)
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
78 * @return a pointer to the new memory pool
314
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
79 * @see ucx_mempool_new_default()
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
80 */
1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
81 UcxMempool *ucx_mempool_new(size_t n);
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
82
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
83 /**
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
84 * Resizes a memory pool.
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
85 *
314
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
86 * This function will fail if the new capacity is not sufficient for the
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
87 * present data.
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
88 *
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
89 * @param pool the pool to resize
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
90 * @param newcap the new capacity
314
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
91 * @return zero on success or non-zero on failure
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
92 */
1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
93 int ucx_mempool_chcap(UcxMempool *pool, size_t newcap);
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
94
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
95 /**
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
96 * Allocates pooled memory.
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
97 *
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
98 * @param pool the memory pool
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
99 * @param n amount of memory to allocate
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
100 * @return a pointer to the allocated memory
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
101 * @see ucx_allocator_malloc()
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
102 */
1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103 void *ucx_mempool_malloc(UcxMempool *pool, size_t n);
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
104 /**
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
105 * Allocates a pooled memory array.
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
106 *
70
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
107 * The content of the allocated memory is set to zero.
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
108 *
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
109 * @param pool the memory pool
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
110 * @param nelem amount of elements to allocate
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
111 * @param elsize amount of memory per element
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
112 * @return a pointer to the allocated memory
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
113 * @see ucx_allocator_calloc()
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
114 */
1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
115 void *ucx_mempool_calloc(UcxMempool *pool, size_t nelem, size_t elsize);
17
11dffb40cd91 new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
116
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
117 /**
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
118 * Reallocates pooled memory.
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
119 *
255
bf19378aed58 updates UCX to version 0.11
Mike Becker <universe@uap-core.de>
parents: 169
diff changeset
120 * If the memory to be reallocated is not contained by the specified pool, the
bf19378aed58 updates UCX to version 0.11
Mike Becker <universe@uap-core.de>
parents: 169
diff changeset
121 * behavior is undefined.
17
11dffb40cd91 new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
122 *
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
123 * @param pool the memory pool
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
124 * @param ptr a pointer to the memory that shall be reallocated
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
125 * @param n the new size of the memory
70
88092b88ec00 ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 40
diff changeset
126 * @return a pointer to the new location of the memory
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
127 * @see ucx_allocator_realloc()
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
128 */
1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
129 void *ucx_mempool_realloc(UcxMempool *pool, void *ptr, size_t n);
17
11dffb40cd91 new dav_query function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 5
diff changeset
130
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
131 /**
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
132 * Frees pooled memory.
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
133 *
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
134 * Before freeing the memory, the specified destructor function (if any)
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
135 * is called.
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
136 *
255
bf19378aed58 updates UCX to version 0.11
Mike Becker <universe@uap-core.de>
parents: 169
diff changeset
137 * If you specify memory, that is not pooled by the specified memory pool, the
314
8722a668fb2a updates ucx version (most importantly this adds the new sstrstr implementation)
Mike Becker <universe@uap-core.de>
parents: 255
diff changeset
138 * program will terminate with a call to <code>abort()</code>.
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
139 *
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
140 * @param pool the memory pool
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
141 * @param ptr a pointer to the memory that shall be freed
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
142 * @see ucx_mempool_set_destr()
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
143 */
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
144 void ucx_mempool_free(UcxMempool *pool, void *ptr);
1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
145
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
146 /**
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
147 * Destroys a memory pool.
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
148 *
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
149 * For each element the destructor function (if any) is called and the element
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
150 * is freed.
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
151 *
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
152 * Each of the registered destructor function that has no corresponding element
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
153 * within the pool (namely those registered by ucx_mempool_reg_destr) is
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
154 * called interleaving with the element destruction, but with guarantee to the
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
155 * order in which they were registered (FIFO order).
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
156 *
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
157 *
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
158 * @param pool the mempool to destroy
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
159 */
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
160 void ucx_mempool_destroy(UcxMempool *pool);
1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
161
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
162 /**
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
163 * Sets a destructor function for the specified memory.
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
164 *
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
165 * The destructor is automatically called when the memory is freed or the
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
166 * pool is destroyed.
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
167 *
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
168 * The only requirement for the specified memory is, that it <b>MUST</b> be
255
bf19378aed58 updates UCX to version 0.11
Mike Becker <universe@uap-core.de>
parents: 169
diff changeset
169 * pooled memory by a UcxMempool or an element-compatible mempool. The pointer
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
170 * to the destructor function is saved in a reserved area before the actual
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
171 * memory.
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
172 *
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
173 * @param ptr pooled memory
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
174 * @param func a pointer to the destructor function
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
175 * @see ucx_mempool_free()
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
176 * @see ucx_mempool_destroy()
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
177 */
1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
178 void ucx_mempool_set_destr(void *ptr, ucx_destructor func);
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
179
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
180 /**
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
181 * Registers a destructor function for the specified (non-pooled) memory.
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
182 *
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
183 * This is useful, if you have memory that has not been allocated by a mempool,
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
184 * but shall be managed by a mempool.
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
185 *
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
186 * This function creates an entry in the specified mempool and the memory will
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
187 * therefore (logically) convert to pooled memory.
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
188 *
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
189 * @param pool the memory pool
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
190 * @param ptr data the destructor is registered for
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
191 * @param destr a pointer to the destructor function
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
192 */
1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
193 void ucx_mempool_reg_destr(UcxMempool *pool, void *ptr, ucx_destructor destr);
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
194
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
195 #ifdef __cplusplus
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
196 }
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
197 #endif
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
198
5
88625853ae74 new webdav api + repository and key configuration + aes encryption
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1
diff changeset
199 #endif /* UCX_MEMPOOL_H */
1
1bcaac272cdf added existing source code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
200

mercurial