paul@93 | 1 | /* |
paul@93 | 2 | * A page queue abstraction. |
paul@93 | 3 | * |
paul@344 | 4 | * Copyright (C) 2021, 2022 Paul Boddie <paul@boddie.org.uk> |
paul@93 | 5 | * |
paul@93 | 6 | * This program is free software; you can redistribute it and/or |
paul@93 | 7 | * modify it under the terms of the GNU General Public License as |
paul@93 | 8 | * published by the Free Software Foundation; either version 2 of |
paul@93 | 9 | * the License, or (at your option) any later version. |
paul@93 | 10 | * |
paul@93 | 11 | * This program is distributed in the hope that it will be useful, |
paul@93 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@93 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@93 | 14 | * GNU General Public License for more details. |
paul@93 | 15 | * |
paul@93 | 16 | * You should have received a copy of the GNU General Public License |
paul@93 | 17 | * along with this program; if not, write to the Free Software |
paul@93 | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@93 | 19 | * Boston, MA 02110-1301, USA |
paul@93 | 20 | */ |
paul@93 | 21 | |
paul@6 | 22 | #pragma once |
paul@6 | 23 | |
paul@6 | 24 | #include <list> |
paul@6 | 25 | |
paul@94 | 26 | #include <mem/flexpage.h> |
paul@94 | 27 | #include <mem/memory.h> |
paul@94 | 28 | #include <fsserver/page_owner.h> |
paul@6 | 29 | |
paul@6 | 30 | |
paul@6 | 31 | |
paul@6 | 32 | /* Collection types. */ |
paul@6 | 33 | |
paul@6 | 34 | typedef struct { Flexpage *flexpage; PageOwner *owner; } QueueEntry; |
paul@6 | 35 | typedef std::list<QueueEntry> Queue; |
paul@6 | 36 | |
paul@6 | 37 | |
paul@6 | 38 | |
paul@70 | 39 | /* A queue of managed pages. */ |
paul@6 | 40 | |
paul@6 | 41 | class PageQueue |
paul@6 | 42 | { |
paul@74 | 43 | protected: |
paul@74 | 44 | /* Helper methods. */ |
paul@74 | 45 | |
paul@74 | 46 | virtual void discard(Queue &queue, Memory *memory); |
paul@74 | 47 | |
paul@70 | 48 | public: |
paul@94 | 49 | virtual ~PageQueue(); |
paul@72 | 50 | |
paul@74 | 51 | virtual void close(Memory *memory) = 0; |
paul@74 | 52 | |
paul@70 | 53 | virtual void pop(PageOwner **owner, Flexpage **flexpage) = 0; |
paul@6 | 54 | |
paul@70 | 55 | virtual void push(PageOwner *owner, Flexpage *flexpage) = 0; |
paul@6 | 56 | |
paul@70 | 57 | virtual void push_front(PageOwner *owner, Flexpage *flexpage) = 0; |
paul@6 | 58 | |
paul@70 | 59 | virtual bool remove(PageOwner *owner, Flexpage *flexpage) = 0; |
paul@6 | 60 | }; |
paul@6 | 61 | |
paul@6 | 62 | // vim: tabstop=4 expandtab shiftwidth=4 |