ucx/cx/mempool.h

changeset 16
04c9f8d8f03b
parent 11
0aa8cbd7912e
child 21
5ea41679e15d
equal deleted inserted replaced
15:862ab606ee06 16:04c9f8d8f03b
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 /** 28 /**
29 * \file mempool.h 29 * @file mempool.h
30 * \brief Interface for memory pool implementations. 30 * @brief Interface for memory pool implementations.
31 * \author Mike Becker 31 * @author Mike Becker
32 * \author Olaf Wintermann 32 * @author Olaf Wintermann
33 * \copyright 2-Clause BSD License 33 * @copyright 2-Clause BSD License
34 */ 34 */
35 35
36 #ifndef UCX_MEMPOOL_H 36 #ifndef UCX_MEMPOOL_H
37 #define UCX_MEMPOOL_H 37 #define UCX_MEMPOOL_H
38 38
78 /** 78 /**
79 * Deallocates a memory pool and frees the managed memory. 79 * Deallocates a memory pool and frees the managed memory.
80 * 80 *
81 * @param pool the memory pool to free 81 * @param pool the memory pool to free
82 */ 82 */
83 cx_attr_export
83 void cxMempoolFree(CxMempool *pool); 84 void cxMempoolFree(CxMempool *pool);
84 85
85 /** 86 /**
86 * Creates an array-based memory pool with a shared destructor function. 87 * Creates an array-based memory pool with a shared destructor function.
87 * 88 *
88 * This destructor MUST NOT free the memory. 89 * This destructor MUST NOT free the memory.
89 * 90 *
90 * @param capacity the initial capacity of the pool 91 * @param capacity the initial capacity of the pool
91 * @param destr optional destructor function to use for allocated memory 92 * @param destr optional destructor function to use for allocated memory
92 * @return the created memory pool or \c NULL if allocation failed 93 * @return the created memory pool or @c NULL if allocation failed
93 */ 94 */
94 cx_attr_nodiscard 95 cx_attr_nodiscard
95 cx_attr_malloc 96 cx_attr_malloc
96 cx_attr_dealloc(cxMempoolFree, 1) 97 cx_attr_dealloc(cxMempoolFree, 1)
98 cx_attr_export
97 CxMempool *cxMempoolCreate(size_t capacity, cx_destructor_func destr); 99 CxMempool *cxMempoolCreate(size_t capacity, cx_destructor_func destr);
98 100
99 /** 101 /**
100 * Creates a basic array-based memory pool. 102 * Creates a basic array-based memory pool.
101 * 103 *
102 * @param capacity the initial capacity of the pool 104 * @param capacity (@c size_t) the initial capacity of the pool
103 * @return the created memory pool or \c NULL if allocation failed 105 * @return (@c CxMempool*) the created memory pool or @c NULL if allocation failed
104 */ 106 */
105 #define cxBasicMempoolCreate(capacity) cxMempoolCreate(capacity, NULL) 107 #define cxMempoolCreateSimple(capacity) cxMempoolCreate(capacity, NULL)
106 108
107 /** 109 /**
108 * Sets the destructor function for a specific allocated memory object. 110 * Sets the destructor function for a specific allocated memory object.
109 * 111 *
110 * If the memory is not managed by a UCX memory pool, the behavior is undefined. 112 * If the memory is not managed by a UCX memory pool, the behavior is undefined.
112 * 114 *
113 * @param memory the object allocated in the pool 115 * @param memory the object allocated in the pool
114 * @param fnc the destructor function 116 * @param fnc the destructor function
115 */ 117 */
116 cx_attr_nonnull 118 cx_attr_nonnull
119 cx_attr_export
117 void cxMempoolSetDestructor( 120 void cxMempoolSetDestructor(
118 void *memory, 121 void *memory,
119 cx_destructor_func fnc 122 cx_destructor_func fnc
120 ); 123 );
121 124
126 * The destructor MUST NOT free the memory. 129 * The destructor MUST NOT free the memory.
127 * 130 *
128 * @param memory the object allocated in the pool 131 * @param memory the object allocated in the pool
129 */ 132 */
130 cx_attr_nonnull 133 cx_attr_nonnull
134 cx_attr_export
131 void cxMempoolRemoveDestructor(void *memory); 135 void cxMempoolRemoveDestructor(void *memory);
132 136
133 /** 137 /**
134 * Registers foreign memory with this pool. 138 * Registers foreign memory with this pool.
135 * 139 *
139 * If that allocation fails, this function will return non-zero. 143 * If that allocation fails, this function will return non-zero.
140 * 144 *
141 * @param pool the pool 145 * @param pool the pool
142 * @param memory the object to register (MUST NOT be already allocated in the pool) 146 * @param memory the object to register (MUST NOT be already allocated in the pool)
143 * @param destr the destructor function 147 * @param destr the destructor function
144 * @return zero on success, non-zero on failure 148 * @retval zero success
149 * @retval non-zero failure
145 */ 150 */
146 cx_attr_nonnull 151 cx_attr_nonnull
152 cx_attr_export
147 int cxMempoolRegister( 153 int cxMempoolRegister(
148 CxMempool *pool, 154 CxMempool *pool,
149 void *memory, 155 void *memory,
150 cx_destructor_func destr 156 cx_destructor_func destr
151 ); 157 );

mercurial