include/native/heap.h

Go to the documentation of this file.
00001 
00022 #ifndef _XENO_HEAP_H
00023 #define _XENO_HEAP_H
00024 
00025 #include <nucleus/synch.h>
00026 #include <nucleus/heap.h>
00027 #include <native/types.h>
00028 
00029 /* Creation flags. */
00030 #define H_PRIO     XNSYNCH_PRIO /* Pend by task priority order. */
00031 #define H_FIFO     XNSYNCH_FIFO /* Pend by FIFO order. */
00032 #define H_DMA      0x100        /* Use memory suitable for DMA. */
00033 #define H_MAPPABLE 0x200        /* Memory is mappable to user-space. */
00034 #define H_SINGLE   0x400        /* Manage as single-block area. */
00035 #define H_SHARED   (H_MAPPABLE|H_SINGLE) /* I.e. shared memory segment. */
00036 
00037 typedef struct rt_heap_info {
00038 
00039     int nwaiters;               /* !< Number of pending tasks. */
00040 
00041     int mode;                   /* !< Creation mode. */
00042 
00043     size_t heapsize;            /* !< Requested heap size. */
00044 
00045     size_t usablemem;           /* !< Available heap memory. */
00046 
00047     size_t usedmem;             /* !< Amount of memory used. */
00048 
00049     char name[XNOBJECT_NAME_LEN]; /* !< Symbolic name. */
00050 
00051 } RT_HEAP_INFO;
00052 
00053 typedef struct rt_heap_placeholder {
00054 
00055     xnhandle_t opaque;
00056 
00057     void *opaque2;
00058 
00059     caddr_t mapbase;
00060 
00061     size_t mapsize;
00062 
00063 } RT_HEAP_PLACEHOLDER;
00064 
00065 #if defined(__KERNEL__) || defined(__XENO_SIM__)
00066 
00067 #include <native/ppd.h>
00068 
00069 #define XENO_HEAP_MAGIC 0x55550808
00070 
00071 typedef struct rt_heap {
00072 
00073     unsigned magic;   /* !< Magic code - must be first */
00074 
00075     xnsynch_t synch_base; /* !< Base synchronization object. */
00076 
00077     xnheap_t heap_base; /* !< Internal heap object. */
00078 
00079     int mode;           /* !< Creation mode. */
00080 
00081     size_t csize;       /* !< Original size at creation. */
00082 
00083     void *sba;          /* !< Single block ara (H_SINGLE only) */
00084 
00085     xnhandle_t handle;  /* !< Handle in registry -- zero if unregistered. */
00086 
00087     char name[XNOBJECT_NAME_LEN]; /* !< Symbolic name. */
00088 
00089 #ifdef CONFIG_XENO_OPT_PERVASIVE
00090     pid_t cpid;                 /* !< Creator's pid. */
00091 #endif /* CONFIG_XENO_OPT_PERVASIVE */
00092 
00093     xnholder_t rlink;           /* !< Link in resource queue. */
00094 
00095 #define rlink2heap(ln)          container_of(ln, RT_HEAP, rlink)
00096 
00097     xnqueue_t *rqueue;          /* !< Backpointer to resource queue. */
00098 
00099 } RT_HEAP;
00100 
00101 #ifdef __cplusplus
00102 extern "C" {
00103 #endif
00104 
00105 #ifdef CONFIG_XENO_OPT_NATIVE_HEAP
00106 
00107 int __native_heap_pkg_init(void);
00108 
00109 void __native_heap_pkg_cleanup(void);
00110 
00111 static inline void __native_heap_flush_rq(xnqueue_t *rq)
00112 {
00113         xeno_flush_rq(RT_HEAP, rq, heap);
00114 }
00115 
00116 #else /* !CONFIG_XENO_OPT_NATIVE_HEAP */
00117 
00118 #define __native_heap_pkg_init()                ({ 0; })
00119 #define __native_heap_pkg_cleanup()             do { } while(0)
00120 #define __native_heap_flush_rq(rq)              do { } while(0)
00121 
00122 #endif /* !CONFIG_XENO_OPT_NATIVE_HEAP */
00123 
00124 #ifdef __cplusplus
00125 }
00126 #endif
00127 
00128 #else /* !(__KERNEL__ || __XENO_SIM__) */
00129 
00130 typedef RT_HEAP_PLACEHOLDER RT_HEAP;
00131 
00132 #ifdef __cplusplus
00133 extern "C" {
00134 #endif
00135 
00136 int rt_heap_bind(RT_HEAP *heap,
00137                  const char *name,
00138                  RTIME timeout);
00139 
00140 int rt_heap_unbind(RT_HEAP *heap);
00141 
00142 #ifdef __cplusplus
00143 }
00144 #endif
00145 
00146 #endif /* __KERNEL__ || __XENO_SIM__ */
00147 
00148 #ifdef __cplusplus
00149 extern "C" {
00150 #endif
00151 
00152 /* Public interface. */
00153 
00154 int rt_heap_create(RT_HEAP *heap,
00155                    const char *name,
00156                    size_t heapsize,
00157                    int mode);
00158 
00159 int rt_heap_delete(RT_HEAP *heap);
00160 
00161 int rt_heap_alloc(RT_HEAP *heap,
00162                   size_t size,
00163                   RTIME timeout,
00164                   void **blockp);
00165 
00166 int rt_heap_free(RT_HEAP *heap,
00167                  void *block);
00168 
00169 int rt_heap_inquire(RT_HEAP *heap,
00170                     RT_HEAP_INFO *info);
00171 
00172 #ifdef __cplusplus
00173 }
00174 #endif
00175 
00176 #endif /* !_XENO_HEAP_H */

Generated on Mon Mar 24 18:02:40 2008 for Xenomai API by  doxygen 1.5.3