1 #include "pipe_paging.h" 2 3 PipePaging::PipePaging(offset_t size) 4 : _size(size) 5 { 6 } 7 8 /* Detach one endpoint. */ 9 10 void PipePaging::detach() 11 { 12 if (!_endpoints) 13 return; 14 else 15 _endpoints--; 16 17 /* Return if the other endpoint is attached. */ 18 19 if (_endpoints) 20 return; 21 22 /* Discard all regions from the pipe. */ 23 24 while (!_regions.empty()) 25 { 26 PageMapper *mapper = _regions.front(); 27 28 _regions.pop_front(); 29 mapper->detach(); 30 delete mapper; 31 } 32 } 33 34 /* Add a region to the sequence. */ 35 36 void PipePaging::add_region(PageMapper *mapper) 37 { 38 _regions.push_back(mapper); 39 } 40 41 /* Return the first region in the sequence. */ 42 43 PageMapper *PipePaging::first_region() 44 { 45 return _regions.front(); 46 } 47 48 /* Return the next region for the reader. If only a single region remains, with 49 the reader wishing to move to the next, return NULL. */ 50 51 PageMapper *PipePaging::next_region() 52 { 53 if (_regions.size() > 1) 54 { 55 /* Discard the accessor from the current region. */ 56 57 if (_accessors.size() > _regions.size()) 58 _accessors.pop_front(); 59 60 /* Detach and discard the current page mapper. */ 61 62 PageMapper *mapper = _regions.front(); 63 64 _regions.pop_front(); 65 mapper->detach(); 66 delete mapper; 67 68 /* Return the next region. */ 69 70 return _regions.front(); 71 } 72 else 73 return NULL; 74 } 75 76 /* Initialise an accessor for a region. */ 77 78 PipeAccessor *PipePaging::accessor() 79 { 80 PipeAccessor accessor; 81 82 _accessors.push_back(accessor); 83 return &_accessors.back(); 84 } 85 86 // vim: tabstop=4 expandtab shiftwidth=4