4 #include "lock_guard.h"
6 #include "slab_cache.h"
9 class Dbg_page_info_table;
11 class Dbg_page_info : public cxx::S_list_item
13 friend class Dbg_page_info_table;
16 Page_number const _pfn;
17 typedef unsigned long Buf[5];
20 char *b() { return reinterpret_cast<char*>(_buf); }
21 char const *b() const { return reinterpret_cast<char const*>(_buf); }
23 typedef Slab_cache Allocator;
26 void *operator new (size_t) throw() { return alloc()->alloc(); }
27 void operator delete (void *p, size_t) { alloc()->free(p); }
29 enum { Buffer_size = sizeof(Buf) };
31 Dbg_page_info(Page_number pfn) : _pfn(pfn) {}
33 bool match(Page_number p) { return _pfn == p; }
37 { return reinterpret_cast<T*>(b()); }
41 { return reinterpret_cast<T const*>(b()); }
44 class Dbg_page_info_table
47 typedef cxx::S_list_bss<Dbg_page_info> List;
55 enum { Hash_tab_size = 1024 };
58 Entry _tab[Hash_tab_size];
59 static unsigned hash(Page_number p) { return p.value() % Hash_tab_size; }
64 IMPLEMENTATION [debug]:
66 #include "kmem_slab.h"
69 static Dbg_page_info_table _t;
73 Dbg_page_info::table()
78 static Kmem_slab_t<Dbg_page_info> _dbg_page_info_allocator("Dbg_page_info");
81 Dbg_page_info::Allocator *
82 Dbg_page_info::alloc()
83 { return &_dbg_page_info_allocator; }
86 PUBLIC template<typename B, typename E> static inline
88 Dbg_page_info_table::find(B const &b, E const &e, Page_number p)
90 for (B i = b; i != e; ++i)
98 Dbg_page_info_table::operator [] (Page_number pfn) const
100 Entry &e = const_cast<Dbg_page_info_table*>(this)->_tab[hash(pfn)];
101 auto g = lock_guard(e.l);
102 // we know that *end() is NULL
103 return *find(e.h.begin(), e.h.end(), pfn);
108 Dbg_page_info_table::insert(Dbg_page_info *i)
110 Entry *e = &_tab[hash(i->_pfn)];
111 auto g = lock_guard(e->l);
117 Dbg_page_info_table::remove(Page_number pfn)
119 Entry *e = &_tab[hash(pfn)];
120 auto g = lock_guard(e->l);
122 List::Iterator i = find(e->h.begin(), e->h.end(), pfn);
126 Dbg_page_info *r = *i;