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