Xenomai  3.0-rc3
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;
60  size_t heapsize;
66  size_t usablemem;
70  size_t usedmem;
74  char name[XNOBJECT_NAME_LEN];
75 };
76 
77 typedef struct RT_HEAP_INFO RT_HEAP_INFO;
78 
79 #ifdef __cplusplus
80 extern "C" {
81 #endif
82 
83 int rt_heap_create(RT_HEAP *heap,
84  const char *name,
85  size_t heapsize,
86  int mode);
87 
88 int rt_heap_delete(RT_HEAP *heap);
89 
90 int rt_heap_alloc_timed(RT_HEAP *heap,
91  size_t size,
92  const struct timespec *abs_timeout,
93  void **blockp);
94 
95 static inline
96 int rt_heap_alloc_until(RT_HEAP *heap,
97  size_t size, RTIME timeout, void **blockp)
98 {
99  struct timespec ts;
100  return rt_heap_alloc_timed(heap, size,
101  alchemy_abs_timeout(timeout, &ts),
102  blockp);
103 }
104 
105 static inline
106 int rt_heap_alloc(RT_HEAP *heap,
107  size_t size, RTIME timeout, void **blockp)
108 {
109  struct timespec ts;
110  return rt_heap_alloc_timed(heap, size,
111  alchemy_rel_timeout(timeout, &ts),
112  blockp);
113 }
114 
115 int rt_heap_free(RT_HEAP *heap,
116  void *block);
117 
118 int rt_heap_inquire(RT_HEAP *heap,
119  RT_HEAP_INFO *info);
120 
121 int rt_heap_bind(RT_HEAP *heap,
122  const char *name,
123  RTIME timeout);
124 
125 int rt_heap_unbind(RT_HEAP *heap);
126 
127 #ifdef __cplusplus
128 }
129 #endif
130 
133 #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:106
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:504
size_t heapsize
Overall size of heap (in bytes).
Definition: heap.h:60
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:96
size_t usablemem
Maximum amount of memory available from the heap.
Definition: heap.h:66
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:414
int rt_heap_unbind(RT_HEAP *heap)
Unbind from a heap.
Definition: heap.c:658
char name[XNOBJECT_NAME_LEN]
Name of heap.
Definition: heap.h:74
int rt_heap_bind(RT_HEAP *heap, const char *name, RTIME timeout)
Bind to a heap.
Definition: heap.c:636
size_t usedmem
Amount of heap memory currently consumed.
Definition: heap.h:70
Heap status descriptor.
Definition: heap.h:47
int rt_heap_inquire(RT_HEAP *heap, RT_HEAP_INFO *info)
Query heap status.
Definition: heap.c:567