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