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