1 /* 2 * A page queue abstraction. 3 * 4 * Copyright (C) 2021 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 <list> 25 #include <map> 26 27 #include <mem/flexpage.h> 28 #include <mem/memory.h> 29 #include <fsserver/page_owner.h> 30 31 32 33 /* Collection types. */ 34 35 typedef struct { Flexpage *flexpage; PageOwner *owner; } QueueEntry; 36 typedef std::list<QueueEntry> Queue; 37 38 typedef std::pair<Flexpage *, Queue::iterator> Position; 39 typedef std::map<Flexpage *, Queue::iterator> Positions; 40 41 42 43 /* A queue of managed pages. */ 44 45 class PageQueue 46 { 47 protected: 48 49 /* Helper methods. */ 50 51 virtual void discard(Queue &queue, Memory *memory); 52 53 virtual bool remove(Queue &queue, Positions &positions, PageOwner *owner, Flexpage *flexpage); 54 55 public: 56 virtual ~PageQueue(); 57 58 virtual void close(Memory *memory) = 0; 59 60 virtual void pop(PageOwner **owner, Flexpage **flexpage) = 0; 61 62 virtual void push(PageOwner *owner, Flexpage *flexpage) = 0; 63 64 virtual void push_front(PageOwner *owner, Flexpage *flexpage) = 0; 65 66 virtual bool remove(PageOwner *owner, Flexpage *flexpage) = 0; 67 }; 68 69 // vim: tabstop=4 expandtab shiftwidth=4