]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/ferret/lib/local_names/local_names.c
update
[l4.git] / l4 / pkg / ferret / lib / local_names / local_names.c
1 /**
2  * \file   ferret/lib/local_names/local_names.c
3  * \brief  Manage local names for kernel objects (e.g., Fiasco's User
4  *         Semaphores)
5  *
6  * \date   2007-06-20
7  * \author Martin Pohlack  <mp26@os.inf.tu-dresden.de>
8  */
9 /*
10  * (c) 2006-2009 Technische Universität Dresden
11  * This file is part of TUD:OS and distributed under the terms of the
12  * GNU General Public License 2.
13  * Please see the COPYING-GPL-2 file for details.
14  */
15 #include <stdlib.h>
16
17 #include <l4/l4rm/l4rm.h>
18 #include <l4/log/l4log.h>
19 #include <l4/sys/l4int.h>
20 #include <l4/util/bitops.h>
21
22 #include <l4/ferret/types.h>
23 #include <l4/ferret/local_names.h>
24
25 #define MAX_LOCAL_NAMES 256  // fixme: the kernel should export this constant
26
27 static l4_mword_t
28 bitarray[(MAX_LOCAL_NAMES + L4_MWORD_BITS - 1) / L4_MWORD_BITS];
29
30 int ferret_local_names_reserve(void)
31 {
32     int i;
33     for (i = 1; i < MAX_LOCAL_NAMES; i++)
34     {
35         if (! l4util_bts(i % L4_MWORD_BITS, &(bitarray[i / L4_MWORD_BITS])))
36         {
37             break;
38         }
39     }
40     if (i >= MAX_LOCAL_NAMES)
41         return 0;
42     else
43         return i;
44 }
45
46 void ferret_local_names_dispose(int index)
47 {
48     if (index < MAX_LOCAL_NAMES)
49     {
50         l4util_clear_bit(index % L4_MWORD_BITS,
51                          &(bitarray[index / L4_MWORD_BITS]));
52     }
53 }