Xenomai API  2.6.5
heap.h
Go to the documentation of this file.
1 
22 #ifndef _XENO_HEAP_H
23 #define _XENO_HEAP_H
24 
25 #include <nucleus/synch.h>
26 #include <nucleus/heap.h>
27 #include <native/types.h>
28 
29 /* Creation flags. */
30 #define H_PRIO XNSYNCH_PRIO /* Pend by task priority order. */
31 #define H_FIFO XNSYNCH_FIFO /* Pend by FIFO order. */
32 #define H_DMA 0x100 /* Use memory suitable for DMA. */
33 #define H_MAPPABLE 0x200 /* Memory is mappable to user-space. */
34 #define H_SINGLE 0x400 /* Manage as single-block area. */
35 #define H_SHARED (H_MAPPABLE|H_SINGLE) /* I.e. shared memory segment. */
36 #define H_NONCACHED 0x800
37 #define H_DMA32 0x1000 /* Use memory suitable for DMA32. */
38 
43 typedef struct rt_heap_info {
44 
45  int nwaiters; /* !< Number of pending tasks. */
46 
47  int mode; /* !< Creation mode. */
48 
49  size_t heapsize; /* !< Requested heap size. */
50 
51  size_t usablemem; /* !< Available heap memory. */
52 
53  size_t usedmem; /* !< Amount of memory used. */
54 
55  char name[XNOBJECT_NAME_LEN]; /* !< Symbolic name. */
56 
57  unsigned long phys_addr; /* !< Physical address. */
58 
59 } RT_HEAP_INFO;
60 
61 typedef struct rt_heap_placeholder {
62  xnhandle_t opaque;
63  void *opaque2;
64  caddr_t mapbase;
65  size_t mapsize;
66  unsigned long area;
67 } RT_HEAP_PLACEHOLDER;
68 
69 #if defined(__KERNEL__) || defined(__XENO_SIM__)
70 
71 #include <native/ppd.h>
72 
73 #define XENO_HEAP_MAGIC 0x55550808
74 
75 typedef struct rt_heap {
76 
77  unsigned magic; /* !< Magic code - must be first */
78 
79  xnsynch_t synch_base; /* !< Base synchronization object. */
80 
81  xnheap_t heap_base; /* !< Internal heap object. */
82 
83  int mode; /* !< Creation mode. */
84 
85  size_t csize; /* !< Original size at creation. */
86 
87  void *sba; /* !< Single block ara (H_SINGLE only) */
88 
89  xnhandle_t handle; /* !< Handle in registry -- zero if unregistered. */
90 
91  char name[XNOBJECT_NAME_LEN]; /* !< Symbolic name. */
92 
93 #ifdef CONFIG_XENO_OPT_PERVASIVE
94  pid_t cpid; /* !< Creator's pid. */
95 #endif /* CONFIG_XENO_OPT_PERVASIVE */
96 
97  xnholder_t rlink; /* !< Link in resource queue. */
98 
99 #define rlink2heap(ln) container_of(ln, RT_HEAP, rlink)
100 
101  xnqueue_t *rqueue; /* !< Backpointer to resource queue. */
102 
103 } RT_HEAP;
104 
105 #ifdef __cplusplus
106 extern "C" {
107 #endif
108 
109 #ifdef CONFIG_XENO_OPT_NATIVE_HEAP
110 
111 int __native_heap_pkg_init(void);
112 
113 void __native_heap_pkg_cleanup(void);
114 
115 static inline void __native_heap_flush_rq(xnqueue_t *rq)
116 {
117  xeno_flush_rq_norelease(RT_HEAP, rq, heap);
118 }
119 
120 int rt_heap_delete_inner(RT_HEAP *heap,
121  void __user *mapaddr);
122 
123 #else /* !CONFIG_XENO_OPT_NATIVE_HEAP */
124 
125 #define __native_heap_pkg_init() ({ 0; })
126 #define __native_heap_pkg_cleanup() do { } while(0)
127 #define __native_heap_flush_rq(rq) do { } while(0)
128 
129 #endif /* !CONFIG_XENO_OPT_NATIVE_HEAP */
130 
131 #ifdef __cplusplus
132 }
133 #endif
134 
135 #else /* !(__KERNEL__ || __XENO_SIM__) */
136 
137 typedef RT_HEAP_PLACEHOLDER RT_HEAP;
138 
139 #ifdef __cplusplus
140 extern "C" {
141 #endif
142 
143 int rt_heap_bind(RT_HEAP *heap,
144  const char *name,
145  RTIME timeout);
146 
147 int rt_heap_unbind(RT_HEAP *heap);
148 
149 #ifdef __cplusplus
150 }
151 #endif
152 
153 #endif /* __KERNEL__ || __XENO_SIM__ */
154 
155 #ifdef __cplusplus
156 extern "C" {
157 #endif
158 
159 /* Public interface. */
160 
161 int rt_heap_create(RT_HEAP *heap,
162  const char *name,
163  size_t heapsize,
164  int mode);
165 
166 int rt_heap_delete(RT_HEAP *heap);
167 
168 int rt_heap_alloc(RT_HEAP *heap,
169  size_t size,
170  RTIME timeout,
171  void **blockp);
172 
173 int rt_heap_free(RT_HEAP *heap,
174  void *block);
175 
176 int rt_heap_inquire(RT_HEAP *heap,
177  RT_HEAP_INFO *info);
178 
179 #ifdef __cplusplus
180 }
181 #endif
182 
183 #endif /* !_XENO_HEAP_H */
Structure containing heap-information useful to users.
Definition: heap.h:43
int rt_heap_bind(RT_HEAP *heap, const char *name, RTIME timeout)
Bind to a mappable heap.
Definition: heap.c:70
int rt_heap_inquire(RT_HEAP *heap, RT_HEAP_INFO *info)
Inquire about a heap.
Definition: heap.c:122
int rt_heap_create(RT_HEAP *heap, const char *name, size_t heapsize, int mode)
Create a memory heap or a shared memory segment.
Definition: heap.c:49
int rt_heap_delete(RT_HEAP *heap)
Delete a real-time heap.
Definition: heap.c:95
int rt_heap_unbind(RT_HEAP *heap)
Unbind from a mappable heap.
Definition: heap.c:81
This file is part of the Xenomai project.
int rt_heap_free(RT_HEAP *heap, void *block)
Free a block.
Definition: heap.c:117
struct rt_heap_info RT_HEAP_INFO
Structure containing heap-information useful to users.
int rt_heap_alloc(RT_HEAP *heap, size_t size, RTIME timeout, void **blockp)
Allocate a block or return the single segment base.
Definition: heap.c:110
This file is part of the Xenomai project.