RTI Connext Micro  Version 2.4.1.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
reda_bufferpool.h
1 /*
2  * FILE: reda_bufferpool.c - BufferPool interface
3  *
4  * Copyright 2008-2014 Real-Time Innovations, Inc.
5  *
6  * No duplications, whole or partial, manual or electronic, may be made
7  * without express written permission. Any such copies, or
8  * revisions thereof, must display this notice unaltered.
9  * This code contains trade secrets of Real-Time Innovations, Inc.
10  *
11  * Modification History
12  * --------------------
13  * 11mar2013,tk MICRO-171/PR#1051
14  * 25may2012,tk Written
15  *
16  */
17 /*ci
18  * \file
19  *
20  * \brief The REDA BufferPool interface provides a platform independent API to
21  * manage a pool of fixed size elements.
22  *
23  * \defgroup REDA_BufferPoolClass REDA BufferPool
24  * \ingroup REDAModule
25  *
26  * \details
27  *
28  * The REDA BufferPool interface defines an API manage a fixed number of
29  * fixed sized elements. It is important to note that the number of elements
30  * in the pool cannot grow beyond what was specified when the pool was created.
31  * Callbacks can be installed to be notified when the buffer pool allocates
32  * a new buffer or free a buffer.
33  */
34 
35 /*ci \addtogroup REDA_BufferPoolClass
36  * @{
37  */
38 #ifndef reda_bufferpool_h
39 #define reda_bufferpool_h
40 
41 #ifndef reda_dll_h
42 #include "reda/reda_dll.h"
43 #endif
44 
45 #ifdef __cplusplus
46 extern "C"
47 {
48 #endif
49 
50 /*ci
51  * \brief REDA_Buffer pool properties specified when a buffer pool is created
52  */
53 struct REDA_BufferPoolProperty
54 {
55  /*ci
56  * \brief The size of an element in the buffer pool. Note that in case the
57  * buffer contains pointers to other memory location, the size must be
58  * the size of the top-level structure only.
59  */
60  RTI_SIZE_T buffer_size;
61 
62  /*ci
63  * \brief The maximum number of buffers managed by the pool
64  */
65  RTI_SIZE_T max_buffers;
66 
67  /*ci
68  * \brief Additional flags to specify the behavior of the pool
69  */
70  RTI_INT32 flags;
71 };
72 
73 /*ci
74  * \def REDA_BUFFERPOOL_FLAG_ARRAY_ALLOC
75  * \brief Create a single array of elements. This could improve memory
76  * utilization for smaller sizes
77  */
78 #define REDA_BUFFERPOOL_FLAG_ARRAY_ALLOC (0x1)
79 
80 /*ci
81  * \def REDA_BufferPoolProperty_INITIALIZER
82  * \brief REDA_BufferPoolProperty initializer
83  */
84 #define REDA_BufferPoolProperty_INITIALIZER \
85 { \
86  0,\
87  0,\
88  0\
89 }
90 
91 /*ci
92  * \def REDA_BUFFERPOOL_UNLIMITED
93  * \brief Constant to indicate an UNLIMITED buffer-pool. Specifying this constant
94  * will result in a run-time error.
95  */
96 #define REDA_BUFFERPOOL_UNLIMITED (0xffffffff)
97 
98 struct REDA_BufferPool;
99 
100 /*ci
101  * \brief Abstract REDA_BufferPool type
102  */
103 typedef struct REDA_BufferPool *REDA_BufferPool_T;
104 
105 /*ci
106  *
107  * \brief REDA_BufferPool initialization function type.
108  *
109  * \details
110  *
111  * For each buffer that is allocated from system memory
112  * REDA buffer calls this function exactly once.
113  *
114  * \param[in] initialize_param Parameter passed to \ref REDA_BufferPool_new
115  * \param[in] buffer Buffer to iniialize
116  *
117  */
118 FUNCTION_MUST_TYPEDEF(
119 RTI_BOOL
120 (*REDA_BufferPool_initializeFunc_T)(void *initialize_param, void *buffer)
121 )
122 
123 /*ci
124  *
125  * \brief REDA_BufferPool finalization type
126  *
127  * \details
128  * For each buffer that is returned to system memory REDA buffer calls
129  * this function exactly once
130  *
131  * \param[in] finalize_param Parameter passed to \ref REDA_BufferPool_new
132  * \param[in] buffer Buffer to finalize
133  */
134 FUNCTION_SHOULD_TYPEDEF(
135 RTI_BOOL
136 (*REDA_BufferPool_finalizeFunc_T)(void *finalize_param, void *buffer)
137 )
138 
139 /*ci
140  * \brief Create a new bufferpool
141  *
142  * \param[in] property BufferPool property. Refer to \ref
143  * REDA_BufferPoolProperty for details.
144  * \param[in] initialize_func Buffer initialization function. This function
145  * is called exactly once for each buffer managed by the pool. NULL
146  * is legal, in which case a buffer is not guaranteed to have a
147  * known state.
148  * \param[in] initialize_param Opaque parameter passed to the initialize_func
149  * \param[in] finalize_func Buffer finalizing function. This function is called
150  * exactly once before a buffer before it is returned to system
151  * memory. NULL is legal, in which case the buffer is returned
152  * as is to the system memory.
153  * \param[in] finalize_param Opaque parameter passed to the finalize_func
154  *
155  * \return Pointer to new buffer pool on success, NULL on failure
156  *
157  * \sa REDA_BufferPool_delete
158  *
159  */
160 MUST_CHECK_RETURN REDADllExport REDA_BufferPool_T
161 REDA_BufferPool_new(struct REDA_BufferPoolProperty *property,
162  REDA_BufferPool_initializeFunc_T initialize_func,
163  void *initialize_param,
164  REDA_BufferPool_finalizeFunc_T finalize_func,
165  void *finalize_param);
166 
167 /*ci
168  *
169  * \brief Delete a bufferpool
170  *
171  * \details
172  *
173  * Return all buffers managed by the buffer-pool to system memory. It is not
174  * legal to delete a buffer-pool with outstanding buffers.
175  *
176  * \param[in] pool BufferPool to delete
177  *
178  * \return RTI_TRUE on success, RTI_FALSE on failure.
179  *
180  * \sa REDA_BufferPool_delete
181  */
182 SHOULD_CHECK_RETURN REDADllExport RTI_BOOL
183 REDA_BufferPool_delete(REDA_BufferPool_T pool);
184 
185 /*ci
186  * \brief Get a buffer from the buffer pool
187  *
188  * \details
189  *
190  * Take a buffer out of the free-pool and return it to the caller for use.
191  * Note that the buffer returned from the pool has only been initialized with
192  * the initialize_func passed to the REDA_BufferPool_new when the pool was
193  * created.
194  *
195  * \param[in] pool BufferPool to get buffer from
196  *
197  * \return pointer to buffer on success, NULL on failure
198  *
199  * \sa REDA_BufferPool_return_buffer
200  */
201 MUST_CHECK_RETURN REDADllExport void*
202 REDA_BufferPool_get_buffer(REDA_BufferPool_T pool);
203 
204 /*ci
205  * \brief Return a buffer to the buffer-pool
206  *
207  * \details
208  *
209  * Return a buffer to the buffer-pool and make it available for future
210  * calls to \ref REDA_BufferPool_get_buffer. Note that the finalize_func
211  * is <em> not </em> called when a buffer is returned to the pool.
212  *
213  * \param[in] pool BufferPool to return buffer to
214  * \param[in] buffer buffer to return to pool
215  *
216  * \return pointer to buffer on success, NULL on failure
217  *
218  * \sa REDA_BufferPool_return_buffer
219  */
220 REDADllExport void
221 REDA_BufferPool_return_buffer(REDA_BufferPool_T pool,void *buffer);
222 
223 #ifdef __cplusplus
224 } /* extern "C" */
225 #endif
226 
227 
228 #endif /* reda_bufferpool_h */
229 
230 /*ci @} */

RTI Connext Micro Version 2.4.1.0 Copyright © Thu Nov 20 2014 Real-Time Innovations, Inc