1.1 --- a/libfsserver/include/fsserver/page_queue.h Sat May 28 23:52:48 2022 +0200 1.2 +++ b/libfsserver/include/fsserver/page_queue.h Sun May 29 00:31:29 2022 +0200 1.3 @@ -1,7 +1,7 @@ 1.4 /* 1.5 * A page queue abstraction. 1.6 * 1.7 - * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk> 1.8 + * Copyright (C) 2021, 2022 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 @@ -22,7 +22,6 @@ 1.13 #pragma once 1.14 1.15 #include <list> 1.16 -#include <map> 1.17 1.18 #include <mem/flexpage.h> 1.19 #include <mem/memory.h> 1.20 @@ -35,9 +34,6 @@ 1.21 typedef struct { Flexpage *flexpage; PageOwner *owner; } QueueEntry; 1.22 typedef std::list<QueueEntry> Queue; 1.23 1.24 -typedef std::pair<Flexpage *, Queue::iterator> Position; 1.25 -typedef std::map<Flexpage *, Queue::iterator> Positions; 1.26 - 1.27 1.28 1.29 /* A queue of managed pages. */ 1.30 @@ -45,13 +41,10 @@ 1.31 class PageQueue 1.32 { 1.33 protected: 1.34 - 1.35 /* Helper methods. */ 1.36 1.37 virtual void discard(Queue &queue, Memory *memory); 1.38 1.39 - virtual bool remove(Queue &queue, Positions &positions, PageOwner *owner, Flexpage *flexpage); 1.40 - 1.41 public: 1.42 virtual ~PageQueue(); 1.43
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/libfsserver/include/fsserver/page_queue_common.h Sun May 29 00:31:29 2022 +0200 2.3 @@ -0,0 +1,48 @@ 2.4 +/* 2.5 + * Common page queue functionality. 2.6 + * 2.7 + * Copyright (C) 2021, 2022 Paul Boddie <paul@boddie.org.uk> 2.8 + * 2.9 + * This program is free software; you can redistribute it and/or 2.10 + * modify it under the terms of the GNU General Public License as 2.11 + * published by the Free Software Foundation; either version 2 of 2.12 + * the License, or (at your option) any later version. 2.13 + * 2.14 + * This program is distributed in the hope that it will be useful, 2.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 2.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2.17 + * GNU General Public License for more details. 2.18 + * 2.19 + * You should have received a copy of the GNU General Public License 2.20 + * along with this program; if not, write to the Free Software 2.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, 2.22 + * Boston, MA 02110-1301, USA 2.23 + */ 2.24 + 2.25 +#pragma once 2.26 + 2.27 +#include <map> 2.28 + 2.29 +#include <fsserver/page_queue.h> 2.30 + 2.31 + 2.32 + 2.33 +/* Collection types. */ 2.34 + 2.35 +typedef std::pair<Flexpage *, Queue::iterator> Position; 2.36 +typedef std::map<Flexpage *, Queue::iterator> Positions; 2.37 + 2.38 + 2.39 + 2.40 +/* Common functionality for specific kinds of queues. */ 2.41 + 2.42 +class PageQueueCommon : public PageQueue 2.43 +{ 2.44 +protected: 2.45 + 2.46 + /* Helper methods. */ 2.47 + 2.48 + virtual bool remove(Queue &queue, Positions &positions, PageOwner *owner, Flexpage *flexpage); 2.49 +}; 2.50 + 2.51 +// vim: tabstop=4 expandtab shiftwidth=4
3.1 --- a/libfsserver/include/fsserver/page_queue_partitioned.h Sat May 28 23:52:48 2022 +0200 3.2 +++ b/libfsserver/include/fsserver/page_queue_partitioned.h Sun May 29 00:31:29 2022 +0200 3.3 @@ -1,7 +1,7 @@ 3.4 /* 3.5 * A page queue retaining two internal collections of memory pages. 3.6 * 3.7 - * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk> 3.8 + * Copyright (C) 2021, 2022 Paul Boddie <paul@boddie.org.uk> 3.9 * 3.10 * This program is free software; you can redistribute it and/or 3.11 * modify it under the terms of the GNU General Public License as 3.12 @@ -24,13 +24,13 @@ 3.13 #include <condition_variable> 3.14 #include <mutex> 3.15 3.16 -#include <fsserver/page_queue.h> 3.17 +#include <fsserver/page_queue_common.h> 3.18 3.19 3.20 3.21 /* Queues of issued and available pages. */ 3.22 3.23 -class PageQueuePartitioned : public PageQueue 3.24 +class PageQueuePartitioned : public PageQueueCommon 3.25 { 3.26 protected: 3.27 Queue _issued, _available;
4.1 --- a/libfsserver/include/fsserver/page_queue_shared.h Sat May 28 23:52:48 2022 +0200 4.2 +++ b/libfsserver/include/fsserver/page_queue_shared.h Sun May 29 00:31:29 2022 +0200 4.3 @@ -1,7 +1,7 @@ 4.4 /* 4.5 * A page queue whose users take turns to access pages. 4.6 * 4.7 - * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk> 4.8 + * Copyright (C) 2021, 2022 Paul Boddie <paul@boddie.org.uk> 4.9 * 4.10 * This program is free software; you can redistribute it and/or 4.11 * modify it under the terms of the GNU General Public License as 4.12 @@ -24,13 +24,13 @@ 4.13 #include <condition_variable> 4.14 #include <mutex> 4.15 4.16 -#include <fsserver/page_queue.h> 4.17 +#include <fsserver/page_queue_common.h> 4.18 4.19 4.20 4.21 /* A queue of issued pages. */ 4.22 4.23 -class PageQueueShared : public PageQueue 4.24 +class PageQueueShared : public PageQueueCommon 4.25 { 4.26 protected: 4.27 Queue _queue;
5.1 --- a/libfsserver/lib/Makefile Sat May 28 23:52:48 2022 +0200 5.2 +++ b/libfsserver/lib/Makefile Sun May 29 00:31:29 2022 +0200 5.3 @@ -82,6 +82,7 @@ 5.4 mapping/masked_page_mapper.cc \ 5.5 mapping/page_mapper.cc \ 5.6 pages/page_queue.cc \ 5.7 + pages/page_queue_common.cc \ 5.8 pages/page_queue_partitioned.cc \ 5.9 pages/page_queue_shared.cc \ 5.10 pages/pages.cc \
6.1 --- a/libfsserver/lib/pages/page_queue.cc Sat May 28 23:52:48 2022 +0200 6.2 +++ b/libfsserver/lib/pages/page_queue.cc Sun May 29 00:31:29 2022 +0200 6.3 @@ -1,7 +1,7 @@ 6.4 /* 6.5 * A page queue abstraction. 6.6 * 6.7 - * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk> 6.8 + * Copyright (C) 2021, 2022 Paul Boddie <paul@boddie.org.uk> 6.9 * 6.10 * This program is free software; you can redistribute it and/or 6.11 * modify it under the terms of the GNU General Public License as 6.12 @@ -27,8 +27,6 @@ 6.13 { 6.14 } 6.15 6.16 - 6.17 - 6.18 void PageQueue::discard(Queue &queue, Memory *memory) 6.19 { 6.20 while (!queue.empty()) 6.21 @@ -41,26 +39,4 @@ 6.22 } 6.23 } 6.24 6.25 -bool PageQueue::remove(Queue &queue, Positions &positions, PageOwner *owner, Flexpage *flexpage) 6.26 -{ 6.27 - Positions::iterator position = positions.find(flexpage); 6.28 - 6.29 - if (position == positions.end()) 6.30 - return false; 6.31 - 6.32 - /* The found owner may be different from the requesting owner or even NULL 6.33 - if another owner has acquired and then purged its pages. Such a purged 6.34 - flexpage is not immediately usable, however. */ 6.35 - 6.36 - Queue::iterator entry = position->second; 6.37 - 6.38 - if ((entry->owner == NULL) || (entry->owner != owner)) 6.39 - return false; 6.40 - 6.41 - queue.erase(entry); 6.42 - positions.erase(position); 6.43 - 6.44 - return true; 6.45 -} 6.46 - 6.47 // vim: tabstop=4 expandtab shiftwidth=4
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 7.2 +++ b/libfsserver/lib/pages/page_queue_common.cc Sun May 29 00:31:29 2022 +0200 7.3 @@ -0,0 +1,48 @@ 7.4 +/* 7.5 + * Common page queue functionality. 7.6 + * 7.7 + * Copyright (C) 2021, 2022 Paul Boddie <paul@boddie.org.uk> 7.8 + * 7.9 + * This program is free software; you can redistribute it and/or 7.10 + * modify it under the terms of the GNU General Public License as 7.11 + * published by the Free Software Foundation; either version 2 of 7.12 + * the License, or (at your option) any later version. 7.13 + * 7.14 + * This program is distributed in the hope that it will be useful, 7.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 7.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 7.17 + * GNU General Public License for more details. 7.18 + * 7.19 + * You should have received a copy of the GNU General Public License 7.20 + * along with this program; if not, write to the Free Software 7.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, 7.22 + * Boston, MA 02110-1301, USA 7.23 + */ 7.24 + 7.25 +#include "page_queue_common.h" 7.26 + 7.27 + 7.28 + 7.29 +bool PageQueueCommon::remove(Queue &queue, Positions &positions, PageOwner *owner, Flexpage *flexpage) 7.30 +{ 7.31 + Positions::iterator position = positions.find(flexpage); 7.32 + 7.33 + if (position == positions.end()) 7.34 + return false; 7.35 + 7.36 + /* The found owner may be different from the requesting owner or even NULL 7.37 + if another owner has acquired and then purged its pages. Such a purged 7.38 + flexpage is not immediately usable, however. */ 7.39 + 7.40 + Queue::iterator entry = position->second; 7.41 + 7.42 + if ((entry->owner == NULL) || (entry->owner != owner)) 7.43 + return false; 7.44 + 7.45 + queue.erase(entry); 7.46 + positions.erase(position); 7.47 + 7.48 + return true; 7.49 +} 7.50 + 7.51 +// vim: tabstop=4 expandtab shiftwidth=4
8.1 --- a/libfsserver/lib/pages/page_queue_partitioned.cc Sat May 28 23:52:48 2022 +0200 8.2 +++ b/libfsserver/lib/pages/page_queue_partitioned.cc Sun May 29 00:31:29 2022 +0200 8.3 @@ -127,7 +127,7 @@ 8.4 8.5 bool PageQueuePartitioned::remove(PageOwner *owner, Flexpage *flexpage) 8.6 { 8.7 - return PageQueue::remove(_issued, _positions, owner, flexpage); 8.8 + return PageQueueCommon::remove(_issued, _positions, owner, flexpage); 8.9 } 8.10 8.11 // vim: tabstop=4 expandtab shiftwidth=4
9.1 --- a/libfsserver/lib/pages/page_queue_shared.cc Sat May 28 23:52:48 2022 +0200 9.2 +++ b/libfsserver/lib/pages/page_queue_shared.cc Sun May 29 00:31:29 2022 +0200 9.3 @@ -1,7 +1,7 @@ 9.4 /* 9.5 * A page queue whose users take turns to access pages. 9.6 * 9.7 - * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk> 9.8 + * Copyright (C) 2021, 2022 Paul Boddie <paul@boddie.org.uk> 9.9 * 9.10 * This program is free software; you can redistribute it and/or 9.11 * modify it under the terms of the GNU General Public License as 9.12 @@ -106,7 +106,7 @@ 9.13 9.14 bool PageQueueShared::remove(PageOwner *owner, Flexpage *flexpage) 9.15 { 9.16 - return PageQueue::remove(_queue, _positions, owner, flexpage); 9.17 + return PageQueueCommon::remove(_queue, _positions, owner, flexpage); 9.18 } 9.19 9.20 // vim: tabstop=4 expandtab shiftwidth=4