00001 00002 #ifndef PAGEPOOL_H 00003 #define PAGEPOOL_H 00004 00005 #include <PtMutex.h> 00006 00007 BOREALIS_NAMESPACE_BEGIN; 00008 00010 class PagePool { 00011 public: 00019 PagePool(unsigned int page_size, unsigned int capacity, 00020 bool locked = true); 00021 00023 ~PagePool(); 00024 00027 void *alloc(); 00028 00030 void free(void *); 00031 00034 unsigned int page_size() const { return _page_size; } 00035 00038 unsigned int capacity() const { return _capacity; } 00039 00041 unsigned int alloced_pages() const { return _alloced_pages; } 00042 00044 unsigned int free_pages() const { return _capacity - _alloced_pages; } 00045 00047 void dump() const; 00048 void dumpNoFreeList() const; 00049 00050 private: 00051 struct FreeNode { 00052 FreeNode *next; 00053 }; 00054 00055 unsigned int _page_size; 00056 unsigned int _capacity; 00057 unsigned int _alloced_pages; 00058 00059 void *_block; 00060 unsigned int _block_size; 00061 bool _locked; 00062 FreeNode *_free_list; 00063 00064 PtMutex _mutex; 00065 }; 00066 00067 BOREALIS_NAMESPACE_END; 00068 00069 #endif