1 #include "memory_incremental.h" 2 #include "pages.h" 3 4 5 6 Pages::Pages(Memory *memory, PageQueue *queue) 7 : _memory(memory), _queue(queue) 8 { 9 } 10 11 Pages::Pages(PageQueue *queue) 12 : _queue(queue) 13 { 14 _memory = new MemoryIncremental(); 15 } 16 17 Pages::~Pages() 18 { 19 _queue->close(_memory); 20 } 21 22 /* Remove the first flexpage in the queue. If its owner exists, remove it from 23 the owner (retiring the content). Return the flexpage for reuse. */ 24 25 Flexpage *Pages::remove() 26 { 27 PageOwner *owner; 28 Flexpage *flexpage; 29 30 _queue->pop(&owner, &flexpage); 31 32 if (owner != NULL) 33 owner->remove(flexpage); 34 35 return flexpage; 36 } 37 38 /* Reserve 'flexpage' by removing it from this collection. */ 39 40 bool Pages::reserve(PageOwner *owner, Flexpage *flexpage) 41 { 42 return _queue->remove(owner, flexpage); 43 } 44 45 /* Obtain a new flexpage. Return the flexpage or None if no new flexpage could 46 be created. */ 47 48 Flexpage *Pages::flexpage() 49 { 50 Region *region = _memory->region(); 51 52 if (region != NULL) 53 return new Flexpage(region); 54 else 55 return NULL; 56 } 57 58 /* Queue an entry associating the given 'owner' and 'flexpage'. */ 59 60 void Pages::queue(PageOwner *owner, Flexpage *flexpage) 61 { 62 _queue->push(owner, flexpage); 63 } 64 65 /* Push an entry for 'flexpage' without owner association for immediate 66 reuse. */ 67 68 void Pages::release(Flexpage *flexpage) 69 { 70 _queue->push_front(NULL, flexpage); 71 } 72 73 // vim: tabstop=4 expandtab shiftwidth=4