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)
60 { return cxx::int_value<Page_number>(p) % Hash_tab_size; }
65 IMPLEMENTATION [debug]:
67 #include "kmem_slab.h"
70 static Dbg_page_info_table _t;
74 Dbg_page_info::table()
79 static Kmem_slab_t<Dbg_page_info> _dbg_page_info_allocator("Dbg_page_info");
82 Dbg_page_info::Allocator *
83 Dbg_page_info::alloc()
84 { return &_dbg_page_info_allocator; }
87 PUBLIC template<typename B, typename E> static inline
89 Dbg_page_info_table::find(B const &b, E const &e, Page_number p)
91 for (B i = b; i != e; ++i)
99 Dbg_page_info_table::operator [] (Page_number pfn) const
101 Entry &e = const_cast<Dbg_page_info_table*>(this)->_tab[hash(pfn)];
102 auto g = lock_guard(e.l);
103 // we know that *end() is NULL
104 return *find(e.h.begin(), e.h.end(), pfn);
109 Dbg_page_info_table::insert(Dbg_page_info *i)
111 Entry *e = &_tab[hash(i->_pfn)];
112 auto g = lock_guard(e->l);
118 Dbg_page_info_table::remove(Page_number pfn)
120 Entry *e = &_tab[hash(pfn)];
121 auto g = lock_guard(e->l);
123 List::Iterator i = find(e->h.begin(), e->h.end(), pfn);
127 Dbg_page_info *r = *i;