paul@65 | 1 | #include "pages_conserving.h" |
paul@65 | 2 | |
paul@66 | 3 | PagesConserving::PagesConserving(Memory *memory) |
paul@70 | 4 | : PageCollection(memory) |
paul@65 | 5 | { |
paul@70 | 6 | _queue = &_page_queue; |
paul@65 | 7 | } |
paul@65 | 8 | |
paul@65 | 9 | PagesConserving::PagesConserving() |
paul@70 | 10 | : PageCollection() |
paul@65 | 11 | { |
paul@70 | 12 | _queue = &_page_queue; |
paul@65 | 13 | } |
paul@65 | 14 | |
paul@65 | 15 | |
paul@65 | 16 | |
paul@65 | 17 | /* Refuse to obtain a new flexpage directly. All flexpages must be obtained from |
paul@65 | 18 | the page queue. */ |
paul@65 | 19 | |
paul@65 | 20 | Flexpage *PagesConserving::flexpage() |
paul@65 | 21 | { |
paul@65 | 22 | return NULL; |
paul@65 | 23 | } |
paul@65 | 24 | |
paul@65 | 25 | |
paul@65 | 26 | |
paul@65 | 27 | /* Decrease the provision of flexpages to pipes. */ |
paul@65 | 28 | |
paul@66 | 29 | bool PagesConserving::decrease(offset_t size) |
paul@65 | 30 | { |
paul@65 | 31 | // NOTE: Need to remove flexpages from the queue. |
paul@65 | 32 | // NOTE: This might need to happen incrementally in case some pages are not |
paul@65 | 33 | // NOTE: back in the queue for whatever reason. |
paul@65 | 34 | |
paul@65 | 35 | return true; |
paul@65 | 36 | } |
paul@65 | 37 | |
paul@65 | 38 | /* Increase the provision of flexpages to pipes, returning whether allocation |
paul@65 | 39 | succeeded. */ |
paul@65 | 40 | |
paul@66 | 41 | bool PagesConserving::increase(offset_t size) |
paul@65 | 42 | { |
paul@66 | 43 | offset_t allocated_size = 0; |
paul@65 | 44 | std::list<Region *> allocated; |
paul@65 | 45 | std::list<Region *>::iterator it; |
paul@65 | 46 | |
paul@65 | 47 | /* Allocate regions for the defined increment value. */ |
paul@65 | 48 | |
paul@66 | 49 | while (allocated_size < size) |
paul@65 | 50 | { |
paul@65 | 51 | Region *r = _memory->region(); |
paul@65 | 52 | |
paul@65 | 53 | /* Free all allocated regions if not all regions can be allocated. */ |
paul@65 | 54 | |
paul@65 | 55 | if (r == NULL) |
paul@65 | 56 | { |
paul@65 | 57 | for (it = allocated.begin(); it != allocated.end(); it++) |
paul@65 | 58 | _memory->release(r); |
paul@65 | 59 | |
paul@65 | 60 | return false; |
paul@65 | 61 | } |
paul@65 | 62 | |
paul@65 | 63 | allocated.push_back(r); |
paul@66 | 64 | allocated_size += r->size(); |
paul@65 | 65 | } |
paul@65 | 66 | |
paul@65 | 67 | /* Queue flexpages for the regions. */ |
paul@65 | 68 | |
paul@65 | 69 | for (it = allocated.begin(); it != allocated.end(); it++) |
paul@70 | 70 | _queue->push(NULL, new Flexpage(*it)); |
paul@65 | 71 | |
paul@65 | 72 | return true; |
paul@65 | 73 | } |
paul@65 | 74 | |
paul@65 | 75 | // vim: tabstop=4 expandtab shiftwidth=4 |