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