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