Xenomai 3.3.2
Loading...
Searching...
No Matches
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
34struct RT_HEAP {
35 uintptr_t handle;
36};
37
38typedef struct RT_HEAP RT_HEAP;
39
56 int mode;
62 size_t heapsize;
68 size_t usablemem;
74 size_t usedmem;
78 char name[XNOBJECT_NAME_LEN];
79};
80
81typedef struct RT_HEAP_INFO RT_HEAP_INFO;
82
83#ifdef __cplusplus
84extern "C" {
85#endif
86
87int rt_heap_create(RT_HEAP *heap,
88 const char *name,
89 size_t heapsize,
90 int mode);
91
92int rt_heap_delete(RT_HEAP *heap);
93
94int rt_heap_alloc_timed(RT_HEAP *heap,
95 size_t size,
96 const struct timespec *abs_timeout,
97 void **blockp);
98
99static inline
100int 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
109static inline
110int 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
119int rt_heap_free(RT_HEAP *heap,
120 void *block);
121
122int rt_heap_inquire(RT_HEAP *heap,
123 RT_HEAP_INFO *info);
124
125int rt_heap_bind(RT_HEAP *heap,
126 const char *name,
127 RTIME timeout);
128
129int rt_heap_unbind(RT_HEAP *heap);
130
131#ifdef __cplusplus
132}
133#endif
134
137#endif /* _XENOMAI_ALCHEMY_HEAP_H */
int rt_heap_delete(RT_HEAP *heap)
Delete a heap.
Definition heap.c:307
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
int rt_heap_create(RT_HEAP *heap, const char *name, size_t heapsize, int mode)
Create a heap.
Definition heap.c:214
int rt_heap_free(RT_HEAP *heap, void *block)
Release a block to a heap.
Definition heap.c:515
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:423
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 rt_heap_inquire(RT_HEAP *heap, RT_HEAP_INFO *info)
Query heap status.
Definition heap.c:581
int rt_heap_bind(RT_HEAP *heap, const char *name, RTIME timeout)
Bind to a heap.
Definition heap.c:650
int rt_heap_unbind(RT_HEAP *heap)
Unbind from a heap.
Definition heap.c:672
Heap status descriptor .
Definition heap.h:47
int nwaiters
Number of tasks waiting for available memory in rt_heap_alloc().
Definition heap.h:52
char name[XNOBJECT_NAME_LEN]
Name of heap.
Definition heap.h:78
size_t usedmem
Amount of heap memory currently consumed.
Definition heap.h:74
size_t heapsize
Size of heap (in bytes) as given to rt_heap_create().
Definition heap.h:62
int mode
Creation mode flags as given to rt_heap_create().
Definition heap.h:56
size_t usablemem
Maximum amount of memory available from the heap.
Definition heap.h:68