rtai-core/include/xenomai/heap.h

00001 /*
00002  * Copyright (C) 2001,2002,2003 Philippe Gerum <rpm@xenomai.org>.
00003  *
00004  * Xenomai is free software; you can redistribute it and/or modify it
00005  * under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 2 of the License, or
00007  * (at your option) any later version.
00008  *
00009  * Xenomai is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with Xenomai; if not, write to the Free Software Foundation,
00016  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  *
00018  * As a special exception, the RTAI project gives permission
00019  * for additional uses of the text contained in its release of
00020  * Xenomai.
00021  *
00022  * The exception is that, if you link the Xenomai libraries with other
00023  * files to produce an executable, this does not by itself cause the
00024  * resulting executable to be covered by the GNU General Public License.
00025  * Your use of that executable is in no way restricted on account of
00026  * linking the Xenomai libraries code into it.
00027  *
00028  * This exception does not however invalidate any other reasons why
00029  * the executable file might be covered by the GNU General Public
00030  * License.
00031  *
00032  * This exception applies only to the code released by the
00033  * RTAI project under the name Xenomai.  If you copy code from other
00034  * RTAI project releases into a copy of Xenomai, as the General Public
00035  * License permits, the exception does not apply to the code that you
00036  * add in this way.  To avoid misleading anyone as to the status of
00037  * such modified files, you must delete this exception notice from
00038  * them.
00039  *
00040  * If you write modifications of your own for Xenomai, it is your
00041  * choice whether to permit this exception to apply to your
00042  * modifications. If you do not wish that, delete this exception
00043  * notice.
00044  */
00045 
00046 #ifndef _xenomai_heap_h
00047 #define _xenomai_heap_h
00048 
00049 #include "xenomai/mutex.h"
00050 
00051 /*
00052  * CONSTRAINTS:
00053  *
00054  * Minimum page size is 2 ** XNHEAP_MINLOG2 (must be large enough to
00055  * hold a pointer).
00056  *
00057  * Maximum page size is 2 ** XNHEAP_MAXLOG2.
00058  *
00059  * Minimum block size equals the minimum page size.
00060  *
00061  * Requested block size smaller than the minimum block size is
00062  * rounded to the minimum block size.
00063  *
00064  * Requested block size larger than 2 times the page size is rounded
00065  * to the next page boundary and obtained from the free page
00066  * list. So we need a bucket for each power of two between
00067  * XNHEAP_MINLOG2 and XNHEAP_MAXLOG2 inclusive, plus one to honor
00068  * requests ranging from the maximum page size to twice this size.
00069  */
00070 
00071 #define XNHEAP_MINLOG2    3
00072 #define XNHEAP_MAXLOG2    22
00073 #define XNHEAP_MINALLOCSZ (1 << XNHEAP_MINLOG2)
00074 #define XNHEAP_MINALIGNSZ (1 << (XNHEAP_MINLOG2 + 1))
00075 #define XNHEAP_NBUCKETS   (XNHEAP_MAXLOG2 - XNHEAP_MINLOG2 + 2)
00076 #define XNHEAP_MAXEXTSZ   (1 << 24) /* i.e. 16Mo */
00077 
00078 #define XNHEAP_PFREE   0
00079 #define XNHEAP_PCONT   1
00080 #define XNHEAP_PLIST   2
00081 
00082 typedef struct xnextent {
00083 
00084     xnholder_t link;
00085 
00086 #define link2extent(laddr) \
00087 ((xnextent_t *)(((char *)laddr) - (int)(&((xnextent_t *)0)->link)))
00088 
00089     caddr_t membase,    /* Base address of the page array */
00090             memlim,     /* Memory limit of page array */
00091             freelist;   /* Head of the free page list */
00092 
00093     u_char pagemap[1];  /* Beginning of page map */
00094 
00095 } xnextent_t;
00096 
00097 /* Creation flag */
00098 #define XNHEAP_EXTENDABLE 0x1
00099 
00100 /* Allocation flags */
00101 #define XNHEAP_WAIT       0x0
00102 #define XNHEAP_NOWAIT     0x1
00103 
00104 typedef struct xnheap {
00105 
00106     xnflags_t flags;
00107 
00108     xnmutex_t mutex;
00109 
00110     u_long extentsize,
00111            pagesize,
00112            pageshift,
00113            hdrsize,
00114            npages,      /* Number of pages per extent */
00115            ubytes,
00116            maxcont;
00117 
00118     xnqueue_t extents;
00119 
00120     caddr_t buckets[XNHEAP_NBUCKETS];
00121 
00122     XNARCH_DECL_DISPLAY_CONTEXT();
00123 
00124 } xnheap_t;
00125 
00126 extern xnheap_t kheap;
00127 
00128 #define xnheap_page_size(heap)      ((heap)->pagesize)
00129 #define xnheap_page_count(heap)     ((heap)->npages)
00130 #define xnheap_used_mem(heap)       ((heap)->ubytes)
00131 
00132 #ifdef __cplusplus
00133 extern "C" {
00134 #endif
00135 
00136 int xnheap_init(xnheap_t *heap,
00137                 void *heapaddr,
00138                 u_long heapsize,
00139                 u_long pagesize);
00140 
00141 void xnheap_destroy(xnheap_t *heap);
00142 
00143 void *xnheap_alloc(xnheap_t *heap,
00144                    u_long size,
00145                    xnflags_t flags);
00146 
00147 int xnheap_free(xnheap_t *heap,
00148                 void *block);
00149 
00150 #ifdef __cplusplus
00151 }
00152 #endif
00153 
00154 #endif /* !_xenomai_heap_h */

Generated on Sat Jul 24 19:36:04 2004 for RTAI API by doxygen 1.3.4