L4Re/departure

Changeset

544:754959243588
2023-03-24 Paul Boddie raw files shortlog changelog graph Sought to prevent a race condition when deleting pipe paging coordinators.
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	Fri Mar 24 00:46:26 2023 +0100
     1.2 +++ b/libfsserver/include/fsserver/pipe_paging.h	Fri Mar 24 16:14:44 2023 +0100
     1.3 @@ -1,7 +1,7 @@
     1.4  /*
     1.5   * A pipe paging coordinator, permitting memory sharing pipe endpoints.
     1.6   *
     1.7 - * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk>
     1.8 + * Copyright (C) 2021, 2023 Paul Boddie <paul@boddie.org.uk>
     1.9   *
    1.10   * This program is free software; you can redistribute it and/or
    1.11   * modify it under the terms of the GNU General Public License as
    1.12 @@ -21,6 +21,7 @@
    1.13  
    1.14  #pragma once
    1.15  
    1.16 +#include <mutex>
    1.17  #include <set>
    1.18  
    1.19  #include <fsserver/notification.h>
    1.20 @@ -39,6 +40,7 @@
    1.21      Memory *_memory;
    1.22      Pages *_pages;
    1.23      PageQueue *_queue;
    1.24 +    std::mutex _lock;
    1.25  
    1.26      /* Regions acting as files with their own accessors. */
    1.27  
     2.1 --- a/libfsserver/lib/pipes/pipe_pager.cc	Fri Mar 24 00:46:26 2023 +0100
     2.2 +++ b/libfsserver/lib/pipes/pipe_pager.cc	Fri Mar 24 16:14:44 2023 +0100
     2.3 @@ -58,8 +58,6 @@
     2.4      if (_paging == NULL)
     2.5          return;
     2.6  
     2.7 -    unsigned int attached = _paging->detach();
     2.8 -
     2.9      /* Notify the other endpoint and unsubscribe. */
    2.10  
    2.11      _paging->notify_others(_writing ? PipePaging::WRITER : PipePaging::READER,
    2.12 @@ -68,7 +66,7 @@
    2.13  
    2.14      /* Deallocate the paging coordinator if no other endpoints are active. */
    2.15  
    2.16 -    if (!attached)
    2.17 +    if (!_paging->detach())
    2.18      {
    2.19          delete _paging;
    2.20          _paging = NULL;
     3.1 --- a/libfsserver/lib/pipes/pipe_paging.cc	Fri Mar 24 00:46:26 2023 +0100
     3.2 +++ b/libfsserver/lib/pipes/pipe_paging.cc	Fri Mar 24 16:14:44 2023 +0100
     3.3 @@ -81,6 +81,8 @@
     3.4  
     3.5  unsigned int PipePaging::detach()
     3.6  {
     3.7 +    std::lock_guard<std::mutex> guard(_lock);
     3.8 +
     3.9      if (_active_endpoints)
    3.10          _active_endpoints--;
    3.11