# HG changeset patch # User Paul Boddie # Date 1628270814 -7200 # Node ID 211abeb2a17edaf97406a5f426334a5e23071291 # Parent 84362bb6f6b93d09943588a4c1aa770eb81b785a Moved pipe region initialisation into the pipe paging coordinator itself. diff -r 84362bb6f6b9 -r 211abeb2a17e libfsserver/include/fsserver/pipe_paging.h --- a/libfsserver/include/fsserver/pipe_paging.h Fri Aug 06 19:24:56 2021 +0200 +++ b/libfsserver/include/fsserver/pipe_paging.h Fri Aug 06 19:26:54 2021 +0200 @@ -59,6 +59,10 @@ /* Common functionality. */ + virtual PageMapper *_add_region(); + + virtual PageMapper *_next_region(); + virtual void discard_region(unsigned int i); public: @@ -75,6 +79,8 @@ virtual PageMapper *current_region(); + virtual PageMapper *current_region(bool writing); + virtual PageMapper *next_region(); /* Access management. */ diff -r 84362bb6f6b9 -r 211abeb2a17e libfsserver/lib/pipes/pipe_opener_resource.cc --- a/libfsserver/lib/pipes/pipe_opener_resource.cc Fri Aug 06 19:24:56 2021 +0200 +++ b/libfsserver/lib/pipes/pipe_opener_resource.cc Fri Aug 06 19:26:54 2021 +0200 @@ -84,14 +84,6 @@ { PipePager *pager = new PipePager(paging, writing); - /* Initialise the first region. */ - - offset_t populated_size, region_size; - long err = pager->next_region(&populated_size, ®ion_size); - - if (err) - return err; - return ResourceServer(pager).start_thread(endpoint); } diff -r 84362bb6f6b9 -r 211abeb2a17e libfsserver/lib/pipes/pipe_pager.cc --- a/libfsserver/lib/pipes/pipe_pager.cc Fri Aug 06 19:24:56 2021 +0200 +++ b/libfsserver/lib/pipes/pipe_pager.cc Fri Aug 06 19:26:54 2021 +0200 @@ -35,6 +35,11 @@ /* Initialise the size of the paged region. */ _size = _paging->region_size(); + + /* Obtain any initial page mapper, this having been set up in the paging + coordinator. */ + + _mapper = _paging->current_region(_writing); } int PipePager::expected_items() diff -r 84362bb6f6b9 -r 211abeb2a17e libfsserver/lib/pipes/pipe_paging.cc --- a/libfsserver/lib/pipes/pipe_paging.cc Fri Aug 06 19:24:56 2021 +0200 +++ b/libfsserver/lib/pipes/pipe_paging.cc Fri Aug 06 19:26:54 2021 +0200 @@ -41,6 +41,11 @@ for (unsigned int i = 0; i < 2; i++) _regions[i] = NULL; + + /* Initialise a region accessible by reader and writer. */ + + _add_region(); + _next_region(); } /* Return whether one or more endpoints have detached. */ @@ -94,7 +99,7 @@ /* Add a region to the sequence. */ -PageMapper *PipePaging::add_region() +PageMapper *PipePaging::_add_region() { /* If the writer already accesses a different region to the reader, no new region is added. */ @@ -117,6 +122,15 @@ _regions[_writing] = mapper; + /* Return the next region's mapper. */ + + return mapper; +} + +PageMapper *PipePaging::add_region() +{ + PageMapper *mapper = _add_region(); + /* Let the writer notify the reader. */ notify_others(PipePaging::WRITER, NOTIFY_CONTENT_AVAILABLE); @@ -133,12 +147,19 @@ return _regions[_reading]; } +/* Return the current region for reading or writing. */ + +PageMapper *PipePaging::current_region(bool writing) +{ + return _regions[writing ? _writing : _reading]; +} + /* Return the next region for the reader if the writer is using a different one. Otherwise, return NULL. */ -PageMapper *PipePaging::next_region() +PageMapper *PipePaging::_next_region() { - /* If the reader already accesses the same region to the writer, no next + /* If the reader already accesses the same region as the writer, no next region can be obtained. */ if (_reading == _writing) @@ -152,13 +173,20 @@ _reading = 1 - _reading; - /* Let the reader notify the writer. */ - - notify_others(PipePaging::READER, NOTIFY_SPACE_AVAILABLE); - /* Return the next region's mapper. */ return _regions[_reading]; } +PageMapper *PipePaging::next_region() +{ + PageMapper *mapper = _next_region(); + + /* Let the reader notify the writer. */ + + notify_others(PipePaging::READER, NOTIFY_SPACE_AVAILABLE); + + return mapper; +} + // vim: tabstop=4 expandtab shiftwidth=4