1.1 --- a/libfsserver/lib/pipes/pipe_paging.cc Fri Aug 06 19:24:56 2021 +0200
1.2 +++ b/libfsserver/lib/pipes/pipe_paging.cc Fri Aug 06 19:26:54 2021 +0200
1.3 @@ -41,6 +41,11 @@
1.4
1.5 for (unsigned int i = 0; i < 2; i++)
1.6 _regions[i] = NULL;
1.7 +
1.8 + /* Initialise a region accessible by reader and writer. */
1.9 +
1.10 + _add_region();
1.11 + _next_region();
1.12 }
1.13
1.14 /* Return whether one or more endpoints have detached. */
1.15 @@ -94,7 +99,7 @@
1.16
1.17 /* Add a region to the sequence. */
1.18
1.19 -PageMapper *PipePaging::add_region()
1.20 +PageMapper *PipePaging::_add_region()
1.21 {
1.22 /* If the writer already accesses a different region to the reader, no new
1.23 region is added. */
1.24 @@ -117,6 +122,15 @@
1.25
1.26 _regions[_writing] = mapper;
1.27
1.28 + /* Return the next region's mapper. */
1.29 +
1.30 + return mapper;
1.31 +}
1.32 +
1.33 +PageMapper *PipePaging::add_region()
1.34 +{
1.35 + PageMapper *mapper = _add_region();
1.36 +
1.37 /* Let the writer notify the reader. */
1.38
1.39 notify_others(PipePaging::WRITER, NOTIFY_CONTENT_AVAILABLE);
1.40 @@ -133,12 +147,19 @@
1.41 return _regions[_reading];
1.42 }
1.43
1.44 +/* Return the current region for reading or writing. */
1.45 +
1.46 +PageMapper *PipePaging::current_region(bool writing)
1.47 +{
1.48 + return _regions[writing ? _writing : _reading];
1.49 +}
1.50 +
1.51 /* Return the next region for the reader if the writer is using a different one.
1.52 Otherwise, return NULL. */
1.53
1.54 -PageMapper *PipePaging::next_region()
1.55 +PageMapper *PipePaging::_next_region()
1.56 {
1.57 - /* If the reader already accesses the same region to the writer, no next
1.58 + /* If the reader already accesses the same region as the writer, no next
1.59 region can be obtained. */
1.60
1.61 if (_reading == _writing)
1.62 @@ -152,13 +173,20 @@
1.63
1.64 _reading = 1 - _reading;
1.65
1.66 - /* Let the reader notify the writer. */
1.67 -
1.68 - notify_others(PipePaging::READER, NOTIFY_SPACE_AVAILABLE);
1.69 -
1.70 /* Return the next region's mapper. */
1.71
1.72 return _regions[_reading];
1.73 }
1.74
1.75 +PageMapper *PipePaging::next_region()
1.76 +{
1.77 + PageMapper *mapper = _next_region();
1.78 +
1.79 + /* Let the reader notify the writer. */
1.80 +
1.81 + notify_others(PipePaging::READER, NOTIFY_SPACE_AVAILABLE);
1.82 +
1.83 + return mapper;
1.84 +}
1.85 +
1.86 // vim: tabstop=4 expandtab shiftwidth=4