]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/l4re-core/sigma0/server/src/page_alloc.h
Update
[l4.git] / l4 / pkg / l4re-core / sigma0 / server / src / page_alloc.h
1 /*
2  * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
3  *               Alexander Warg <warg@os.inf.tu-dresden.de>
4  *     economic rights: Technische Universität Dresden (Germany)
5  *
6  * This file is part of TUD:OS and distributed under the terms of the
7  * GNU General Public License 2.
8  * Please see the COPYING-GPL-2 file for details.
9  */
10 #ifndef SIGMA0_PAGE_ALLOC_H__
11 #define SIGMA0_PAGE_ALLOC_H__
12
13 #include <l4/sys/consts.h>
14
15 #include <l4/cxx/list_alloc>
16 #include <l4/cxx/slab_alloc>
17
18 class Page_alloc_base
19 {
20 public:
21   typedef cxx::List_alloc Alloc;
22 protected:
23   static Alloc _alloc;
24   static unsigned long _total;
25 public:
26   static void init();
27   static void free(void *m)
28   {
29     allocator()->free(m, L4_PAGESIZE);
30     _total += L4_PAGESIZE;
31   }
32
33   static Alloc *allocator() { return &_alloc; }
34   static unsigned long total() { return _total; }
35 };
36
37 template< typename T >
38 class Page_alloc : public Page_alloc_base
39 {
40 public:
41   enum { can_free = 1 };
42   T *alloc()
43   { return (T*)_alloc.alloc(L4_PAGESIZE,L4_PAGESIZE); }
44
45   void free(T* b)
46   { _alloc.free(b, L4_PAGESIZE); }
47 };
48
49 template< typename Type >
50 class Slab_alloc 
51 : public cxx::Slab_static<Type, L4_PAGESIZE, 2, Page_alloc>
52 {};
53
54
55 #endif