# HG changeset patch # User Paul Boddie # Date 1653777089 -7200 # Node ID 04c54c9aa5409bfd4cdf748f79d9d6f9fcc81677 # Parent 56b3134d0c50d063c8aef7c321c9f379939d8b14 Introduced an intermediate class in the page queue hierarchy. diff -r 56b3134d0c50 -r 04c54c9aa540 libfsserver/include/fsserver/page_queue.h --- a/libfsserver/include/fsserver/page_queue.h Sat May 28 23:52:48 2022 +0200 +++ b/libfsserver/include/fsserver/page_queue.h Sun May 29 00:31:29 2022 +0200 @@ -1,7 +1,7 @@ /* * A page queue abstraction. * - * Copyright (C) 2021 Paul Boddie + * Copyright (C) 2021, 2022 Paul Boddie * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -22,7 +22,6 @@ #pragma once #include -#include #include #include @@ -35,9 +34,6 @@ typedef struct { Flexpage *flexpage; PageOwner *owner; } QueueEntry; typedef std::list Queue; -typedef std::pair Position; -typedef std::map Positions; - /* A queue of managed pages. */ @@ -45,13 +41,10 @@ class PageQueue { protected: - /* Helper methods. */ virtual void discard(Queue &queue, Memory *memory); - virtual bool remove(Queue &queue, Positions &positions, PageOwner *owner, Flexpage *flexpage); - public: virtual ~PageQueue(); diff -r 56b3134d0c50 -r 04c54c9aa540 libfsserver/include/fsserver/page_queue_common.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libfsserver/include/fsserver/page_queue_common.h Sun May 29 00:31:29 2022 +0200 @@ -0,0 +1,48 @@ +/* + * Common page queue functionality. + * + * Copyright (C) 2021, 2022 Paul Boddie + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA + */ + +#pragma once + +#include + +#include + + + +/* Collection types. */ + +typedef std::pair Position; +typedef std::map Positions; + + + +/* Common functionality for specific kinds of queues. */ + +class PageQueueCommon : public PageQueue +{ +protected: + + /* Helper methods. */ + + virtual bool remove(Queue &queue, Positions &positions, PageOwner *owner, Flexpage *flexpage); +}; + +// vim: tabstop=4 expandtab shiftwidth=4 diff -r 56b3134d0c50 -r 04c54c9aa540 libfsserver/include/fsserver/page_queue_partitioned.h --- a/libfsserver/include/fsserver/page_queue_partitioned.h Sat May 28 23:52:48 2022 +0200 +++ b/libfsserver/include/fsserver/page_queue_partitioned.h Sun May 29 00:31:29 2022 +0200 @@ -1,7 +1,7 @@ /* * A page queue retaining two internal collections of memory pages. * - * Copyright (C) 2021 Paul Boddie + * Copyright (C) 2021, 2022 Paul Boddie * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -24,13 +24,13 @@ #include #include -#include +#include /* Queues of issued and available pages. */ -class PageQueuePartitioned : public PageQueue +class PageQueuePartitioned : public PageQueueCommon { protected: Queue _issued, _available; diff -r 56b3134d0c50 -r 04c54c9aa540 libfsserver/include/fsserver/page_queue_shared.h --- a/libfsserver/include/fsserver/page_queue_shared.h Sat May 28 23:52:48 2022 +0200 +++ b/libfsserver/include/fsserver/page_queue_shared.h Sun May 29 00:31:29 2022 +0200 @@ -1,7 +1,7 @@ /* * A page queue whose users take turns to access pages. * - * Copyright (C) 2021 Paul Boddie + * Copyright (C) 2021, 2022 Paul Boddie * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -24,13 +24,13 @@ #include #include -#include +#include /* A queue of issued pages. */ -class PageQueueShared : public PageQueue +class PageQueueShared : public PageQueueCommon { protected: Queue _queue; diff -r 56b3134d0c50 -r 04c54c9aa540 libfsserver/lib/Makefile --- a/libfsserver/lib/Makefile Sat May 28 23:52:48 2022 +0200 +++ b/libfsserver/lib/Makefile Sun May 29 00:31:29 2022 +0200 @@ -82,6 +82,7 @@ mapping/masked_page_mapper.cc \ mapping/page_mapper.cc \ pages/page_queue.cc \ + pages/page_queue_common.cc \ pages/page_queue_partitioned.cc \ pages/page_queue_shared.cc \ pages/pages.cc \ diff -r 56b3134d0c50 -r 04c54c9aa540 libfsserver/lib/pages/page_queue.cc --- a/libfsserver/lib/pages/page_queue.cc Sat May 28 23:52:48 2022 +0200 +++ b/libfsserver/lib/pages/page_queue.cc Sun May 29 00:31:29 2022 +0200 @@ -1,7 +1,7 @@ /* * A page queue abstraction. * - * Copyright (C) 2021 Paul Boddie + * Copyright (C) 2021, 2022 Paul Boddie * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -27,8 +27,6 @@ { } - - void PageQueue::discard(Queue &queue, Memory *memory) { while (!queue.empty()) @@ -41,26 +39,4 @@ } } -bool PageQueue::remove(Queue &queue, Positions &positions, PageOwner *owner, Flexpage *flexpage) -{ - Positions::iterator position = positions.find(flexpage); - - if (position == positions.end()) - return false; - - /* The found owner may be different from the requesting owner or even NULL - if another owner has acquired and then purged its pages. Such a purged - flexpage is not immediately usable, however. */ - - Queue::iterator entry = position->second; - - if ((entry->owner == NULL) || (entry->owner != owner)) - return false; - - queue.erase(entry); - positions.erase(position); - - return true; -} - // vim: tabstop=4 expandtab shiftwidth=4 diff -r 56b3134d0c50 -r 04c54c9aa540 libfsserver/lib/pages/page_queue_common.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libfsserver/lib/pages/page_queue_common.cc Sun May 29 00:31:29 2022 +0200 @@ -0,0 +1,48 @@ +/* + * Common page queue functionality. + * + * Copyright (C) 2021, 2022 Paul Boddie + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA + */ + +#include "page_queue_common.h" + + + +bool PageQueueCommon::remove(Queue &queue, Positions &positions, PageOwner *owner, Flexpage *flexpage) +{ + Positions::iterator position = positions.find(flexpage); + + if (position == positions.end()) + return false; + + /* The found owner may be different from the requesting owner or even NULL + if another owner has acquired and then purged its pages. Such a purged + flexpage is not immediately usable, however. */ + + Queue::iterator entry = position->second; + + if ((entry->owner == NULL) || (entry->owner != owner)) + return false; + + queue.erase(entry); + positions.erase(position); + + return true; +} + +// vim: tabstop=4 expandtab shiftwidth=4 diff -r 56b3134d0c50 -r 04c54c9aa540 libfsserver/lib/pages/page_queue_partitioned.cc --- a/libfsserver/lib/pages/page_queue_partitioned.cc Sat May 28 23:52:48 2022 +0200 +++ b/libfsserver/lib/pages/page_queue_partitioned.cc Sun May 29 00:31:29 2022 +0200 @@ -127,7 +127,7 @@ bool PageQueuePartitioned::remove(PageOwner *owner, Flexpage *flexpage) { - return PageQueue::remove(_issued, _positions, owner, flexpage); + return PageQueueCommon::remove(_issued, _positions, owner, flexpage); } // vim: tabstop=4 expandtab shiftwidth=4 diff -r 56b3134d0c50 -r 04c54c9aa540 libfsserver/lib/pages/page_queue_shared.cc --- a/libfsserver/lib/pages/page_queue_shared.cc Sat May 28 23:52:48 2022 +0200 +++ b/libfsserver/lib/pages/page_queue_shared.cc Sun May 29 00:31:29 2022 +0200 @@ -1,7 +1,7 @@ /* * A page queue whose users take turns to access pages. * - * Copyright (C) 2021 Paul Boddie + * Copyright (C) 2021, 2022 Paul Boddie * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -106,7 +106,7 @@ bool PageQueueShared::remove(PageOwner *owner, Flexpage *flexpage) { - return PageQueue::remove(_queue, _positions, owner, flexpage); + return PageQueueCommon::remove(_queue, _positions, owner, flexpage); } // vim: tabstop=4 expandtab shiftwidth=4