paul@93 | 1 | /* |
paul@93 | 2 | * A page queue abstraction. |
paul@93 | 3 | * |
paul@93 | 4 | * Copyright (C) 2021 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@74 | 22 | #include "page_queue.h" |
paul@74 | 23 | |
paul@74 | 24 | |
paul@74 | 25 | |
paul@94 | 26 | PageQueue::~PageQueue() |
paul@94 | 27 | { |
paul@94 | 28 | } |
paul@94 | 29 | |
paul@94 | 30 | |
paul@94 | 31 | |
paul@74 | 32 | void PageQueue::discard(Queue &queue, Memory *memory) |
paul@74 | 33 | { |
paul@74 | 34 | while (!queue.empty()) |
paul@74 | 35 | { |
paul@74 | 36 | Flexpage *flexpage = queue.front().flexpage; |
paul@74 | 37 | |
paul@74 | 38 | queue.pop_front(); |
paul@74 | 39 | memory->release(flexpage->region); |
paul@74 | 40 | delete flexpage; |
paul@74 | 41 | } |
paul@74 | 42 | } |
paul@74 | 43 | |
paul@74 | 44 | bool PageQueue::remove(Queue &queue, Positions &positions, PageOwner *owner, Flexpage *flexpage) |
paul@74 | 45 | { |
paul@74 | 46 | Positions::iterator position = positions.find(flexpage); |
paul@74 | 47 | |
paul@74 | 48 | if (position == positions.end()) |
paul@74 | 49 | return false; |
paul@74 | 50 | |
paul@74 | 51 | /* The found owner may be different from the requesting owner or even NULL |
paul@74 | 52 | if another owner has acquired and then purged its pages. Such a purged |
paul@74 | 53 | flexpage is not immediately usable, however. */ |
paul@74 | 54 | |
paul@74 | 55 | Queue::iterator entry = position->second; |
paul@74 | 56 | |
paul@74 | 57 | if ((entry->owner == NULL) || (entry->owner != owner)) |
paul@74 | 58 | return false; |
paul@74 | 59 | |
paul@74 | 60 | queue.erase(entry); |
paul@74 | 61 | positions.erase(position); |
paul@74 | 62 | |
paul@74 | 63 | return true; |
paul@74 | 64 | } |
paul@74 | 65 | |
paul@74 | 66 | // vim: tabstop=4 expandtab shiftwidth=4 |