Xenomai  3.0.5
heap.h
1 /*
2  * Copyright (C) 2011 Philippe Gerum <rpm@xenomai.org>.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13 
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  */
18 #ifndef _XENOMAI_ALCHEMY_HEAP_H
19 #define _XENOMAI_ALCHEMY_HEAP_H
20 
21 #include <stdint.h>
22 #include <alchemy/timer.h>
23 
30 #define H_PRIO 0x1 /* Pend by task priority order. */
31 #define H_FIFO 0x0 /* Pend by FIFO order. */
32 #define H_SINGLE 0x4 /* Manage as single-block area. */
33 
34 struct RT_HEAP {
35  uintptr_t handle;
36 };
37 
38 typedef struct RT_HEAP RT_HEAP;
39 
47 struct RT_HEAP_INFO {
52  int nwaiters;
56  int mode;
62  size_t heapsize;
68  size_t usablemem;
74  size_t usedmem;
78  char name[XNOBJECT_NAME_LEN];
79 };
80 
81 typedef struct RT_HEAP_INFO RT_HEAP_INFO;
82 
83 #ifdef __cplusplus
84 extern "C" {
85 #endif
86 
87 int rt_heap_create(RT_HEAP *heap,
88  const char *name,
89  size_t heapsize,
90  int mode);
91 
92 int rt_heap_delete(RT_HEAP *heap);
93 
94 int rt_heap_alloc_timed(RT_HEAP *heap,
95  size_t size,
96  const struct timespec *abs_timeout,
97  void **blockp);
98 
99 static inline
100 int rt_heap_alloc_until(RT_HEAP *heap,
101  size_t size, RTIME timeout, void **blockp)
102 {
103  struct timespec ts;
104  return rt_heap_alloc_timed(heap, size,
105  alchemy_abs_timeout(timeout, &ts),
106  blockp);
107 }
108 
109 static inline
110 int rt_heap_alloc(RT_HEAP *heap,
111  size_t size, RTIME timeout, void **blockp)
112 {
113  struct timespec ts;
114  return rt_heap_alloc_timed(heap, size,
115  alchemy_rel_timeout(timeout, &ts),
116  blockp);
117 }
118 
119 int rt_heap_free(RT_HEAP *heap,
120  void *block);
121 
122 int rt_heap_inquire(RT_HEAP *heap,
123  RT_HEAP_INFO *info);
124 
125 int rt_heap_bind(RT_HEAP *heap,
126  const char *name,
127  RTIME timeout);
128 
129 int rt_heap_unbind(RT_HEAP *heap);
130 
131 #ifdef __cplusplus
132 }
133 #endif
134 
137 #endif /* _XENOMAI_ALCHEMY_HEAP_H */
int mode
Creation mode flags as given to rt_heap_create().
Definition: heap.h:56
int rt_heap_delete(RT_HEAP *heap)
Delete a heap.
Definition: heap.c:309
int rt_heap_create(RT_HEAP *heap, const char *name, size_t heapsize, int mode)
Create a heap.
Definition: heap.c:215
static int rt_heap_alloc(RT_HEAP *heap, size_t size, RTIME timeout, void **blockp)
Allocate a block from a heap (with relative scalar timeout).
Definition: heap.h:110
int nwaiters
Number of tasks waiting for available memory in rt_heap_alloc().
Definition: heap.h:52
int rt_heap_free(RT_HEAP *heap, void *block)
Release a block to a heap.
Definition: heap.c:513
size_t heapsize
Size of heap (in bytes) as given to rt_heap_create().
Definition: heap.h:62
static int rt_heap_alloc_until(RT_HEAP *heap, size_t size, RTIME timeout, void **blockp)
Allocate a block from a heap (with absolute scalar timeout).
Definition: heap.h:100
size_t usablemem
Maximum amount of memory available from the heap.
Definition: heap.h:68
int rt_heap_alloc_timed(RT_HEAP *heap, size_t size, const struct timespec *abs_timeout, void **blockp)
Allocate a block from a heap.
Definition: heap.c:421
int rt_heap_unbind(RT_HEAP *heap)
Unbind from a heap.
Definition: heap.c:670
char name[XNOBJECT_NAME_LEN]
Name of heap.
Definition: heap.h:78
int rt_heap_bind(RT_HEAP *heap, const char *name, RTIME timeout)
Bind to a heap.
Definition: heap.c:648
size_t usedmem
Amount of heap memory currently consumed.
Definition: heap.h:74
Heap status descriptor.
Definition: heap.h:47
int rt_heap_inquire(RT_HEAP *heap, RT_HEAP_INFO *info)
Query heap status.
Definition: heap.c:579