L4Re/departure

libfsserver/include/fsserver/pipe_paging.h

618:7123a7307a82
8 months ago Paul Boddie Introduced some debugging output control.
     1 /*     2  * A pipe paging coordinator, permitting memory sharing pipe endpoints.     3  *     4  * Copyright (C) 2021, 2023 Paul Boddie <paul@boddie.org.uk>     5  *     6  * This program is free software; you can redistribute it and/or     7  * modify it under the terms of the GNU General Public License as     8  * published by the Free Software Foundation; either version 2 of     9  * the License, or (at your option) any later version.    10  *    11  * This program is distributed in the hope that it will be useful,    12  * but WITHOUT ANY WARRANTY; without even the implied warranty of    13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    14  * GNU General Public License for more details.    15  *    16  * You should have received a copy of the GNU General Public License    17  * along with this program; if not, write to the Free Software    18  * Foundation, Inc., 51 Franklin Street, Fifth Floor,    19  * Boston, MA  02110-1301, USA    20  */    21     22 #pragma once    23     24 #include <mutex>    25 #include <set>    26     27 #include <fsserver/notification.h>    28 #include <fsserver/page_mapper.h>    29 #include <fsserver/pages.h>    30 #include <fsserver/pipe_accessor.h>    31     32     33     34 /* Pipe paging support, maintaining the sequence of active regions or sections    35    in a pipe. */    36     37 class PipePaging : public NotificationSupport    38 {    39 protected:    40     Memory *_memory;    41     Pages *_pages;    42     PageQueue *_queue;    43     std::mutex _lock;    44     45     /* Regions acting as files with their own accessors. */    46     47     PageMapper *_regions[2];    48     PipeAccessor _accessors[2];    49     50     /* The first region is initially exposed to both reader and writer. */    51     52     int _reading = 0, _writing = 0;    53     54     /* Pipe section/region size. */    55     56     offset_t _size;    57     58     /* Endpoint status. */    59     60     unsigned int _active_endpoints = 2;    61     62     /* Common functionality. */    63     64     virtual PageMapper *_add_region();    65     66     virtual PageMapper *_next_region();    67     68     virtual void discard_region(unsigned int i);    69     70 public:    71     explicit PipePaging(Memory *memory, offset_t size);    72     73     virtual ~PipePaging();    74     75     virtual unsigned int detach();    76     77     virtual offset_t region_size()    78     { return _size; }    79     80     /* Region management. */    81     82     virtual PageMapper *add_region();    83     84     virtual PageMapper *current_region();    85     86     virtual PageMapper *current_region(bool writing);    87     88     virtual PageMapper *next_region();    89     90     /* Access management. */    91     92     virtual int closed();    93     94     /* Special values for various arrays. */    95     96     enum PipePagingRoles : unsigned int    97     {    98         READER = 0,    99         WRITER = 1,   100     };   101 };   102    103 // vim: tabstop=4 expandtab shiftwidth=4