L4Re/departure

Changeset

199:31144210aa37
2021-09-11 Paul Boddie raw files shortlog changelog graph Introduced deletion of pipe paging objects, previously neglected.
libfsserver/include/fsserver/pipe_paging.h (file) libfsserver/lib/pipes/pipe_pager.cc (file) libfsserver/lib/pipes/pipe_paging.cc (file)
     1.1 --- a/libfsserver/include/fsserver/pipe_paging.h	Sat Sep 11 01:32:34 2021 +0200
     1.2 +++ b/libfsserver/include/fsserver/pipe_paging.h	Sat Sep 11 19:44:57 2021 +0200
     1.3 @@ -68,7 +68,9 @@
     1.4  public:
     1.5      explicit PipePaging(Memory *memory, offset_t size);
     1.6  
     1.7 -    virtual void detach();
     1.8 +    virtual ~PipePaging();
     1.9 +
    1.10 +    virtual unsigned int detach();
    1.11  
    1.12      virtual offset_t region_size()
    1.13      { return _size; }
     2.1 --- a/libfsserver/lib/pipes/pipe_pager.cc	Sat Sep 11 01:32:34 2021 +0200
     2.2 +++ b/libfsserver/lib/pipes/pipe_pager.cc	Sat Sep 11 19:44:57 2021 +0200
     2.3 @@ -60,11 +60,22 @@
     2.4  
     2.5  void PipePager::close()
     2.6  {
     2.7 -    _paging->detach();
     2.8 +    if (_paging == NULL)
     2.9 +        return;
    2.10 +
    2.11 +    unsigned int attached = _paging->detach();
    2.12  
    2.13      /* Notify the other endpoint. */
    2.14  
    2.15      _paging->notify_others(_writing ? PipePaging::WRITER : PipePaging::READER, NOTIFY_PEER_CLOSED);
    2.16 +
    2.17 +    /* Deallocate the paging coordinator if no other endpoints are active. */
    2.18 +
    2.19 +    if (!attached)
    2.20 +    {
    2.21 +        delete _paging;
    2.22 +        _paging = NULL;
    2.23 +    }
    2.24  }
    2.25  
    2.26  /* Support paging. */
     3.1 --- a/libfsserver/lib/pipes/pipe_paging.cc	Sat Sep 11 01:32:34 2021 +0200
     3.2 +++ b/libfsserver/lib/pipes/pipe_paging.cc	Sat Sep 11 19:44:57 2021 +0200
     3.3 @@ -46,39 +46,8 @@
     3.4      _next_region();
     3.5  }
     3.6  
     3.7 -/* Return whether one or more endpoints have detached. */
     3.8 -
     3.9 -int PipePaging::closed()
    3.10 -{
    3.11 -    return _active_endpoints < 2;
    3.12 -}
    3.13 -
    3.14 -void PipePaging::discard_region(unsigned int i)
    3.15 +PipePaging::~PipePaging()
    3.16  {
    3.17 -    PageMapper *mapper = _regions[i];
    3.18 -
    3.19 -    if (mapper != NULL)
    3.20 -    {
    3.21 -        mapper->detach();
    3.22 -        _regions[i] = NULL;
    3.23 -        delete mapper;
    3.24 -    }
    3.25 -}
    3.26 -
    3.27 -/* Detach one endpoint. */
    3.28 -
    3.29 -void PipePaging::detach()
    3.30 -{
    3.31 -    if (!_active_endpoints)
    3.32 -        return;
    3.33 -    else
    3.34 -        _active_endpoints--;
    3.35 -
    3.36 -    /* Return if the other endpoint is attached. */
    3.37 -
    3.38 -    if (_active_endpoints)
    3.39 -        return;
    3.40 -
    3.41      /* Discard all regions from the pipe. */
    3.42  
    3.43      for (unsigned int i = 0; i < 2; i++)
    3.44 @@ -95,6 +64,37 @@
    3.45      delete _memory;
    3.46  }
    3.47  
    3.48 +/* Return whether one or more endpoints have detached. */
    3.49 +
    3.50 +int PipePaging::closed()
    3.51 +{
    3.52 +    return _active_endpoints < 2;
    3.53 +}
    3.54 +
    3.55 +/* Detach one endpoint, returning the number still active. */
    3.56 +
    3.57 +unsigned int PipePaging::detach()
    3.58 +{
    3.59 +    if (_active_endpoints)
    3.60 +        _active_endpoints--;
    3.61 +
    3.62 +    return _active_endpoints;
    3.63 +}
    3.64 +
    3.65 +/* Discard a region. */
    3.66 +
    3.67 +void PipePaging::discard_region(unsigned int i)
    3.68 +{
    3.69 +    PageMapper *mapper = _regions[i];
    3.70 +
    3.71 +    if (mapper != NULL)
    3.72 +    {
    3.73 +        mapper->detach();
    3.74 +        _regions[i] = NULL;
    3.75 +        delete mapper;
    3.76 +    }
    3.77 +}
    3.78 +
    3.79  /* Add a region to the sequence. */
    3.80  
    3.81  PageMapper *PipePaging::_add_region()