Xenomai 3.3.2
Loading...
Searching...
No Matches
map.h
1/*
2 * Copyright (C) 2007 Philippe Gerum <rpm@xenomai.org>.
3 *
4 * Xenomai is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published
6 * by the Free Software Foundation; either version 2 of the License,
7 * or (at your option) any later version.
8 *
9 * Xenomai is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with Xenomai; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
17 * 02111-1307, USA.
18 */
19#ifndef _COBALT_KERNEL_MAP_H
20#define _COBALT_KERNEL_MAP_H
21
22#include <asm/bitsperlong.h>
23
29#define XNMAP_MAX_KEYS (BITS_PER_LONG * BITS_PER_LONG)
30
31struct xnmap {
32 int nkeys;
33 int ukeys;
34 int offset;
35 unsigned long himask;
36 unsigned long himap;
37#define __IDMAP_LONGS ((XNMAP_MAX_KEYS+BITS_PER_LONG-1)/BITS_PER_LONG)
38 unsigned long lomap[__IDMAP_LONGS];
39#undef __IDMAP_LONGS
40 void *objarray[1];
41};
42
43struct xnmap *xnmap_create(int nkeys,
44 int reserve,
45 int offset);
46
47void xnmap_delete(struct xnmap *map);
48
49int xnmap_enter(struct xnmap *map,
50 int key,
51 void *objaddr);
52
53int xnmap_remove(struct xnmap *map,
54 int key);
55
56static inline void *xnmap_fetch_nocheck(struct xnmap *map, int key)
57{
58 int ofkey = key - map->offset;
59 return map->objarray[ofkey];
60}
61
62static inline void *xnmap_fetch(struct xnmap *map, int key)
63{
64 int ofkey = key - map->offset;
65
66 if (ofkey < 0 || ofkey >= map->nkeys)
67 return NULL;
68
69 return map->objarray[ofkey];
70}
71
74#endif /* !_COBALT_KERNEL_MAP_H */
struct xnmap * xnmap_create(int nkeys, int reserve, int offset)
Create a map.
Definition map.c:80
static void * xnmap_fetch_nocheck(struct xnmap *map, int key)
Search an object into a map - unchecked form.
Definition map.h:56
static void * xnmap_fetch(struct xnmap *map, int key)
Search an object into a map.
Definition map.h:62
void xnmap_delete(struct xnmap *map)
Delete a map.
Definition map.c:117
int xnmap_enter(struct xnmap *map, int key, void *objaddr)
Index an object into a map.
Definition map.c:150
int xnmap_remove(struct xnmap *map, int key)
Remove an object reference from a map.
Definition map.c:209