1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Xenomai API: Dynamic memory allocation services.</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.5 -->
<div class="navigation" id="top">
<div class="tabs">
<ul>
<li><a href="main.html"><span>Main Page</span></a></li>
<li><a href="pages.html"><span>Related Pages</span></a></li>
<li><a href="modules.html"><span>Modules</span></a></li>
<li><a href="annotated.html"><span>Data Structures</span></a></li>
<li><a href="files.html"><span>Files</span></a></li>
<li><a href="examples.html"><span>Examples</span></a></li>
<li>
<form action="search.php" method="get">
<table cellspacing="0" cellpadding="0" border="0">
<tr>
<td><label> <u>S</u>earch for </label></td>
<td><input type="text" name="query" value="" size="20" accesskey="s"/></td>
</tr>
</table>
</form>
</li>
</ul>
</div>
</div>
<div class="contents">
<h1>Dynamic memory allocation services.<br>
<small>
[<a class="el" href="group__nucleus.html">Xenomai nucleus.</a>]</small>
</h1>
<p>
<div class="dynheader">
Collaboration diagram for Dynamic memory allocation services.:</div>
<div class="dynsection">
<center><table><tr><td><img src="group__heap.png" border="0" alt="" usemap="#group____heap_map">
<map name="group____heap_map">
<area shape="rect" href="group__nucleus.html" title="Xenomai nucleus." alt="" coords="5,6,131,30"></map></td></tr></table></center>
</div>
<hr><a name="_details"></a><h2>Detailed Description</h2>
Dynamic memory allocation services.<p>
The implementation of the memory allocator follows the algorithm described in a USENIX 1988 paper called "Design of a General Purpose Memory Allocator for the 4.3BSD Unix Kernel" by Marshall K. McKusick and Michael J. Karels. You can find it at various locations on the net, including <a href="http://docs.FreeBSD.org/44doc/papers/kernmalloc.pdf.">http://docs.FreeBSD.org/44doc/papers/kernmalloc.pdf.</a> A minor variation allows this implementation to have 'extendable' heaps when needed, with multiple memory extents providing autonomous page address spaces.<p>
The data structures hierarchy is as follows:<p>
<code> <div class="fragment"><pre class="fragment">
HEAP {
block_buckets[]
extent_queue -------+
} |
V
EXTENT #1 {
{static header}
page_map[npages]
page_array[npages][pagesize]
} -+
|
|
V
EXTENT #n {
{static header}
page_map[npages]
page_array[npages][pagesize]
}
</pre></div> </code>
<p>
<table border="0" cellpadding="0" cellspacing="0">
<tr><td></td></tr>
<tr><td colspan="2"><br><h2>Files</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">file </td><td class="memItemRight" valign="bottom"><a class="el" href="ksrc_2nucleus_2heap_8c.html">heap.c</a></td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">Dynamic memory allocation services. <br></td></tr>
<p>
<tr><td colspan="2"><br><h2>Functions</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="group__heap.html#gd65beaf18754ad1f85c479eaf9219042">xnheap_init</a> (xnheap_t *heap, void *heapaddr, u_long heapsize, u_long pagesize)</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">Initialize a memory heap. <a href="#gd65beaf18754ad1f85c479eaf9219042"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="group__heap.html#g7ab506f024eda1d9030e1bf9494c0781">xnheap_destroy</a> (xnheap_t *heap, void(*flushfn)(xnheap_t *heap, void *extaddr, u_long extsize, void *cookie), void *cookie)</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">Destroys a memory heap. <a href="#g7ab506f024eda1d9030e1bf9494c0781"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">void * </td><td class="memItemRight" valign="bottom"><a class="el" href="group__heap.html#gaa8ae99881c9e6a4f8b56aa79f983bdb">xnheap_alloc</a> (xnheap_t *heap, u_long size)</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">Allocate a memory block from a memory heap. <a href="#gaa8ae99881c9e6a4f8b56aa79f983bdb"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="group__heap.html#gcb0151aaff9d56134c7c217bfa67c816">xnheap_test_and_free</a> (xnheap_t *heap, void *block, int(*ckfn)(void *block))</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">Test and release a memory block to a memory heap. <a href="#gcb0151aaff9d56134c7c217bfa67c816"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="group__heap.html#g5dc4305113cd272cfed62e20e2a12ae6">xnheap_free</a> (xnheap_t *heap, void *block)</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">Release a memory block to a memory heap. <a href="#g5dc4305113cd272cfed62e20e2a12ae6"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="group__heap.html#g4842cb75faa41b2cc3ce8e44cf0beade">xnheap_extend</a> (xnheap_t *heap, void *extaddr, u_long extsize)</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">Extend a memory heap. <a href="#g4842cb75faa41b2cc3ce8e44cf0beade"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="group__heap.html#g548f69835e12bf259b6d417b11338a11">xnheap_schedule_free</a> (xnheap_t *heap, void *block, xnholder_t *link)</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">Schedule a memory block for release. <a href="#g548f69835e12bf259b6d417b11338a11"></a><br></td></tr>
</table>
<hr><h2>Function Documentation</h2>
<a class="anchor" name="gaa8ae99881c9e6a4f8b56aa79f983bdb"></a><!-- doxytag: member="heap.c::xnheap_alloc" ref="gaa8ae99881c9e6a4f8b56aa79f983bdb" args="(xnheap_t *heap, u_long size)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void* xnheap_alloc </td>
<td>(</td>
<td class="paramtype">xnheap_t * </td>
<td class="paramname"> <em>heap</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">u_long </td>
<td class="paramname"> <em>size</em></td><td> </td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td><td width="100%"></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>
Allocate a memory block from a memory heap.
<p>
Allocates a contiguous region of memory from an active memory heap. Such allocation is guaranteed to be time-bounded.<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
<table border="0" cellspacing="2" cellpadding="0">
<tr><td valign="top"></td><td valign="top"><em>heap</em> </td><td>The descriptor address of the heap to get memory from.</td></tr>
<tr><td valign="top"></td><td valign="top"><em>size</em> </td><td>The size in bytes of the requested block. Sizes lower or equal to the page size are rounded either to the minimum allocation size if lower than this value, or to the minimum alignment size if greater or equal to this value. In the current implementation, with MINALLOC = 8 and MINALIGN = 16, a 7 bytes request will be rounded to 8 bytes, and a 17 bytes request will be rounded to 32.</td></tr>
</table>
</dl>
<dl class="return" compact><dt><b>Returns:</b></dt><dd>The address of the allocated region upon success, or NULL if no memory is available from the specified heap.</dd></dl>
Environments:<p>
This service can be called from:<p>
<ul>
<li>Kernel module initialization/cleanup code</li><li>Interrupt service routine</li><li>Kernel-based task</li><li>User-space task</li></ul>
<p>
Rescheduling: never.
<p>Referenced by <a class="el" href="shm_8c-source.html#l00473">ftruncate()</a>, <a class="el" href="ksrc_2skins_2native_2heap_8c-source.html#l00503">rt_heap_alloc()</a>, <a class="el" href="ksrc_2skins_2native_2heap_8c-source.html#l00622">rt_heap_free()</a>, <a class="el" href="ksrc_2skins_2native_2pipe_8c-source.html#l00942">rt_pipe_alloc()</a>, <a class="el" href="ksrc_2skins_2native_2pipe_8c-source.html#l00210">rt_pipe_create()</a>, and <a class="el" href="ksrc_2skins_2native_2queue_8c-source.html#l00423">rt_queue_alloc()</a>.</p>
</div>
</div><p>
<a class="anchor" name="g7ab506f024eda1d9030e1bf9494c0781"></a><!-- doxytag: member="heap.c::xnheap_destroy" ref="g7ab506f024eda1d9030e1bf9494c0781" args="(xnheap_t *heap, void(*flushfn)(xnheap_t *heap, void *extaddr, u_long extsize, void *cookie), void *cookie)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">int xnheap_destroy </td>
<td>(</td>
<td class="paramtype">xnheap_t * </td>
<td class="paramname"> <em>heap</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">void(*)(xnheap_t *heap, void *extaddr, u_long extsize, void *cookie) </td>
<td class="paramname"> <em>flushfn</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">void * </td>
<td class="paramname"> <em>cookie</em></td><td> </td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td><td width="100%"></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>
Destroys a memory heap.
<p>
Destroys a memory heap.<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
<table border="0" cellspacing="2" cellpadding="0">
<tr><td valign="top"></td><td valign="top"><em>heap</em> </td><td>The descriptor address of the destroyed heap.</td></tr>
<tr><td valign="top"></td><td valign="top"><em>flushfn</em> </td><td>If non-NULL, the address of a flush routine which will be called for each extent attached to the heap. This routine can be used by the calling code to further release the heap memory.</td></tr>
<tr><td valign="top"></td><td valign="top"><em>cookie</em> </td><td>If <em>flushfn</em> is non-NULL, <em>cookie</em> is an opaque pointer which will be passed unmodified to <em>flushfn</em>.</td></tr>
</table>
</dl>
<dl class="return" compact><dt><b>Returns:</b></dt><dd>0 is returned on success, or -EBUSY if external mappings are still pending on the heap memory.</dd></dl>
Environments:<p>
This service can be called from:<p>
<ul>
<li>Kernel module initialization/cleanup code</li><li>Kernel-based task</li><li>User-space task</li></ul>
<p>
Rescheduling: never.
<p>Referenced by <a class="el" href="shm_8c-source.html#l00473">ftruncate()</a>, <a class="el" href="ksrc_2skins_2native_2heap_8c-source.html#l00363">rt_heap_delete()</a>, <a class="el" href="ksrc_2skins_2native_2pipe_8c-source.html#l00210">rt_pipe_create()</a>, <a class="el" href="ksrc_2skins_2native_2pipe_8c-source.html#l00356">rt_pipe_delete()</a>, <a class="el" href="ksrc_2skins_2native_2queue_8c-source.html#l00331">rt_queue_delete()</a>, and <a class="el" href="pod_8c-source.html#l00449">xnpod_shutdown()</a>.</p>
</div>
</div><p>
<a class="anchor" name="g4842cb75faa41b2cc3ce8e44cf0beade"></a><!-- doxytag: member="heap.c::xnheap_extend" ref="g4842cb75faa41b2cc3ce8e44cf0beade" args="(xnheap_t *heap, void *extaddr, u_long extsize)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">int xnheap_extend </td>
<td>(</td>
<td class="paramtype">xnheap_t * </td>
<td class="paramname"> <em>heap</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">void * </td>
<td class="paramname"> <em>extaddr</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">u_long </td>
<td class="paramname"> <em>extsize</em></td><td> </td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td><td width="100%"></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>
Extend a memory heap.
<p>
Add a new extent to an existing memory heap.<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
<table border="0" cellspacing="2" cellpadding="0">
<tr><td valign="top"></td><td valign="top"><em>heap</em> </td><td>The descriptor address of the heap to add an extent to.</td></tr>
<tr><td valign="top"></td><td valign="top"><em>extaddr</em> </td><td>The address of the extent memory.</td></tr>
<tr><td valign="top"></td><td valign="top"><em>extsize</em> </td><td>The size of the extent memory (in bytes). In the current implementation, this size must match the one of the initial extent passed to <a class="el" href="group__heap.html#gd65beaf18754ad1f85c479eaf9219042" title="Initialize a memory heap.">xnheap_init()</a>.</td></tr>
</table>
</dl>
<dl class="return" compact><dt><b>Returns:</b></dt><dd>0 is returned upon success, or -EINVAL is returned if <em>extsize</em> differs from the initial extent's size.</dd></dl>
Environments:<p>
This service can be called from:<p>
<ul>
<li>Kernel module initialization/cleanup code</li><li>Interrupt service routine</li><li>Kernel-based task</li><li>User-space task</li></ul>
<p>
Rescheduling: never.
</div>
</div><p>
<a class="anchor" name="g5dc4305113cd272cfed62e20e2a12ae6"></a><!-- doxytag: member="heap.c::xnheap_free" ref="g5dc4305113cd272cfed62e20e2a12ae6" args="(xnheap_t *heap, void *block)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">int xnheap_free </td>
<td>(</td>
<td class="paramtype">xnheap_t * </td>
<td class="paramname"> <em>heap</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">void * </td>
<td class="paramname"> <em>block</em></td><td> </td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td><td width="100%"></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>
Release a memory block to a memory heap.
<p>
Releases a memory region to the memory heap it was previously allocated from.<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
<table border="0" cellspacing="2" cellpadding="0">
<tr><td valign="top"></td><td valign="top"><em>heap</em> </td><td>The descriptor address of the heap to release memory to.</td></tr>
<tr><td valign="top"></td><td valign="top"><em>block</em> </td><td>The address of the region to be returned to the heap.</td></tr>
</table>
</dl>
<dl class="return" compact><dt><b>Returns:</b></dt><dd>0 is returned upon success, or one of the following error codes:</dd></dl>
<ul>
<li>-EFAULT is returned whenever the memory address is outside the heap address space.</li></ul>
<p>
<ul>
<li>-EINVAL is returned whenever the memory address does not represent a valid block.</li></ul>
<p>
Environments:<p>
This service can be called from:<p>
<ul>
<li>Kernel module initialization/cleanup code</li><li>Interrupt service routine</li><li>Kernel-based task</li><li>User-space task</li></ul>
<p>
Rescheduling: never.
<p>References <a class="el" href="ksrc_2nucleus_2heap_8c-source.html#l00569">xnheap_test_and_free()</a>.</p>
<p>Referenced by <a class="el" href="shm_8c-source.html#l00473">ftruncate()</a>, <a class="el" href="ksrc_2skins_2native_2heap_8c-source.html#l00622">rt_heap_free()</a>, <a class="el" href="ksrc_2skins_2native_2pipe_8c-source.html#l00356">rt_pipe_delete()</a>, and <a class="el" href="ksrc_2skins_2native_2pipe_8c-source.html#l00982">rt_pipe_free()</a>.</p>
</div>
</div><p>
<a class="anchor" name="gd65beaf18754ad1f85c479eaf9219042"></a><!-- doxytag: member="heap.c::xnheap_init" ref="gd65beaf18754ad1f85c479eaf9219042" args="(xnheap_t *heap, void *heapaddr, u_long heapsize, u_long pagesize)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">int xnheap_init </td>
<td>(</td>
<td class="paramtype">xnheap_t * </td>
<td class="paramname"> <em>heap</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">void * </td>
<td class="paramname"> <em>heapaddr</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">u_long </td>
<td class="paramname"> <em>heapsize</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">u_long </td>
<td class="paramname"> <em>pagesize</em></td><td> </td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td><td width="100%"></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>
Initialize a memory heap.
<p>
Initializes a memory heap suitable for time-bounded allocation requests of dynamic memory.<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
<table border="0" cellspacing="2" cellpadding="0">
<tr><td valign="top"></td><td valign="top"><em>heap</em> </td><td>The address of a heap descriptor which will be used to store the allocation data. This descriptor must always be valid while the heap is active therefore it must be allocated in permanent memory.</td></tr>
<tr><td valign="top"></td><td valign="top"><em>heapaddr</em> </td><td>The address of the heap storage area. All allocations will be made from the given area in time-bounded mode. Since additional extents can be added to a heap, this parameter is also known as the "initial extent".</td></tr>
<tr><td valign="top"></td><td valign="top"><em>heapsize</em> </td><td>The size in bytes of the initial extent pointed at by <em>heapaddr</em>. <em>heapsize</em> must be a multiple of pagesize and lower than 16 Mbytes. <em>heapsize</em> must be large enough to contain a dynamically-sized internal header. The following formula gives the size of this header:<br>
</td></tr>
</table>
</dl>
H = heapsize, P=pagesize, M=sizeof(struct pagemap), E=sizeof(xnextent_t)<br>
hdrsize = ((H - E) * M) / (M + 1)<br>
<p>
This value is then aligned on the next 16-byte boundary. The routine xnheap_overhead() computes the corrected heap size according to the previous formula.<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
<table border="0" cellspacing="2" cellpadding="0">
<tr><td valign="top"></td><td valign="top"><em>pagesize</em> </td><td>The size in bytes of the fundamental memory page which will be used to subdivide the heap internally. Choosing the right page size is important regarding performance and memory fragmentation issues, so it might be a good idea to take a look at <a href="http://docs.FreeBSD.org/44doc/papers/kernmalloc.pdf">http://docs.FreeBSD.org/44doc/papers/kernmalloc.pdf</a> to pick the best one for your needs. In the current implementation, pagesize must be a power of two in the range [ 8 .. 32768 ] inclusive.</td></tr>
</table>
</dl>
<dl class="return" compact><dt><b>Returns:</b></dt><dd>0 is returned upon success, or one of the following error codes:</dd></dl>
<ul>
<li>-EINVAL is returned whenever a parameter is invalid.</li></ul>
<p>
Environments:<p>
This service can be called from:<p>
<ul>
<li>Kernel module initialization/cleanup code</li><li>Kernel-based task</li><li>User-space task</li></ul>
<p>
Rescheduling: never.
<p>Referenced by <a class="el" href="shm_8c-source.html#l00473">ftruncate()</a>, <a class="el" href="ksrc_2skins_2native_2heap_8c-source.html#l00237">rt_heap_create()</a>, <a class="el" href="ksrc_2skins_2native_2pipe_8c-source.html#l00210">rt_pipe_create()</a>, <a class="el" href="ksrc_2skins_2native_2queue_8c-source.html#l00209">rt_queue_create()</a>, and <a class="el" href="pod_8c-source.html#l00241">xnpod_init()</a>.</p>
</div>
</div><p>
<a class="anchor" name="g548f69835e12bf259b6d417b11338a11"></a><!-- doxytag: member="heap.c::xnheap_schedule_free" ref="g548f69835e12bf259b6d417b11338a11" args="(xnheap_t *heap, void *block, xnholder_t *link)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void xnheap_schedule_free </td>
<td>(</td>
<td class="paramtype">xnheap_t * </td>
<td class="paramname"> <em>heap</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">void * </td>
<td class="paramname"> <em>block</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">xnholder_t * </td>
<td class="paramname"> <em>link</em></td><td> </td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td><td width="100%"></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>
Schedule a memory block for release.
<p>
This routine records a block for later release by xnheap_finalize_free(). This service is useful to lazily free blocks of heap memory when immediate release is not an option, e.g. when active references are still pending on the object for a short time after the call. xnheap_finalize_free() is expected to be eventually called by the client code at some point in the future when actually freeing the idle objects is deemed safe.<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
<table border="0" cellspacing="2" cellpadding="0">
<tr><td valign="top"></td><td valign="top"><em>heap</em> </td><td>The descriptor address of the heap to release memory to.</td></tr>
<tr><td valign="top"></td><td valign="top"><em>block</em> </td><td>The address of the region to be returned to the heap.</td></tr>
<tr><td valign="top"></td><td valign="top"><em>link</em> </td><td>The address of a link member, likely but not necessarily within the released object, which will be used by the heap manager to hold the block in the queue of idle objects.</td></tr>
</table>
</dl>
Environments:<p>
This service can be called from:<p>
<ul>
<li>Kernel module initialization/cleanup code</li><li>Interrupt service routine</li><li>Kernel-based task</li><li>User-space task</li></ul>
<p>
Rescheduling: never.
</div>
</div><p>
<a class="anchor" name="gcb0151aaff9d56134c7c217bfa67c816"></a><!-- doxytag: member="heap.c::xnheap_test_and_free" ref="gcb0151aaff9d56134c7c217bfa67c816" args="(xnheap_t *heap, void *block, int(*ckfn)(void *block))" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">int xnheap_test_and_free </td>
<td>(</td>
<td class="paramtype">xnheap_t * </td>
<td class="paramname"> <em>heap</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">void * </td>
<td class="paramname"> <em>block</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">int(*)(void *block) </td>
<td class="paramname"> <em>ckfn</em></td><td> </td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td><td width="100%"></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>
Test and release a memory block to a memory heap.
<p>
Releases a memory region to the memory heap it was previously allocated from. Before the actual release is performed, an optional user-defined can be invoked to check for additional criteria with respect to the request consistency.<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
<table border="0" cellspacing="2" cellpadding="0">
<tr><td valign="top"></td><td valign="top"><em>heap</em> </td><td>The descriptor address of the heap to release memory to.</td></tr>
<tr><td valign="top"></td><td valign="top"><em>block</em> </td><td>The address of the region to be returned to the heap.</td></tr>
<tr><td valign="top"></td><td valign="top"><em>ckfn</em> </td><td>The address of a user-supplied verification routine which is to be called after the memory address specified by <em>block</em> has been checked for validity. The routine is expected to proceed to further consistency checks, and either return zero upon success, or non-zero upon error. In the latter case, the release process is aborted, and <em>ckfn's</em> return value is passed back to the caller of this service as its error return code. <em>ckfn</em> must not trigger the rescheduling procedure either directly or indirectly.</td></tr>
</table>
</dl>
<dl class="return" compact><dt><b>Returns:</b></dt><dd>0 is returned upon success, or -EINVAL is returned whenever the block is not a valid region of the specified heap. Additional return codes can also be defined locally by the <em>ckfn</em> routine.</dd></dl>
Environments:<p>
This service can be called from:<p>
<ul>
<li>Kernel module initialization/cleanup code</li><li>Interrupt service routine</li><li>Kernel-based task</li><li>User-space task</li></ul>
<p>
Rescheduling: never.
<p>Referenced by <a class="el" href="ksrc_2skins_2native_2queue_8c-source.html#l00498">rt_queue_free()</a>, and <a class="el" href="ksrc_2nucleus_2heap_8c-source.html#l00788">xnheap_free()</a>.</p>
</div>
</div><p>
</div>
<hr size="1"><address style="text-align: right;"><small>Generated on Sun Jun 8 18:08:50 2008 for Xenomai API by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.5 </small></address>
</body>
</html>
|