paul@344 | 1 | /* |
paul@344 | 2 | * Common page queue functionality. |
paul@344 | 3 | * |
paul@344 | 4 | * Copyright (C) 2021, 2022 Paul Boddie <paul@boddie.org.uk> |
paul@344 | 5 | * |
paul@344 | 6 | * This program is free software; you can redistribute it and/or |
paul@344 | 7 | * modify it under the terms of the GNU General Public License as |
paul@344 | 8 | * published by the Free Software Foundation; either version 2 of |
paul@344 | 9 | * the License, or (at your option) any later version. |
paul@344 | 10 | * |
paul@344 | 11 | * This program is distributed in the hope that it will be useful, |
paul@344 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@344 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@344 | 14 | * GNU General Public License for more details. |
paul@344 | 15 | * |
paul@344 | 16 | * You should have received a copy of the GNU General Public License |
paul@344 | 17 | * along with this program; if not, write to the Free Software |
paul@344 | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@344 | 19 | * Boston, MA 02110-1301, USA |
paul@344 | 20 | */ |
paul@344 | 21 | |
paul@344 | 22 | #include "page_queue_common.h" |
paul@344 | 23 | |
paul@344 | 24 | |
paul@344 | 25 | |
paul@344 | 26 | bool PageQueueCommon::remove(Queue &queue, Positions &positions, PageOwner *owner, Flexpage *flexpage) |
paul@344 | 27 | { |
paul@344 | 28 | Positions::iterator position = positions.find(flexpage); |
paul@344 | 29 | |
paul@344 | 30 | if (position == positions.end()) |
paul@344 | 31 | return false; |
paul@344 | 32 | |
paul@344 | 33 | /* The found owner may be different from the requesting owner or even NULL |
paul@344 | 34 | if another owner has acquired and then purged its pages. Such a purged |
paul@344 | 35 | flexpage is not immediately usable, however. */ |
paul@344 | 36 | |
paul@344 | 37 | Queue::iterator entry = position->second; |
paul@344 | 38 | |
paul@344 | 39 | if ((entry->owner == NULL) || (entry->owner != owner)) |
paul@344 | 40 | return false; |
paul@344 | 41 | |
paul@344 | 42 | queue.erase(entry); |
paul@344 | 43 | positions.erase(position); |
paul@344 | 44 | |
paul@344 | 45 | return true; |
paul@344 | 46 | } |
paul@344 | 47 | |
paul@344 | 48 | // vim: tabstop=4 expandtab shiftwidth=4 |