paul@93 | 1 | /* |
paul@93 | 2 | * An access map providing memory corresponding to file regions. |
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@6 | 22 | #pragma once |
paul@6 | 23 | |
paul@94 | 24 | #include <mem/flexpage.h> |
paul@94 | 25 | #include <fsserver/page_owner.h> |
paul@94 | 26 | #include <fsserver/pages.h> |
paul@6 | 27 | |
paul@6 | 28 | #include <map> |
paul@6 | 29 | #include <mutex> |
paul@6 | 30 | |
paul@93 | 31 | |
paul@93 | 32 | |
paul@6 | 33 | /* Collection types. */ |
paul@6 | 34 | |
paul@6 | 35 | typedef std::map<offset_t, Flexpage *> _AccessMap; |
paul@6 | 36 | typedef std::pair<offset_t, Flexpage *> _AccessMapEntry; |
paul@6 | 37 | |
paul@93 | 38 | |
paul@93 | 39 | |
paul@6 | 40 | /* A mapping from file positions to flexpages. */ |
paul@6 | 41 | |
paul@6 | 42 | class AccessMap |
paul@6 | 43 | { |
paul@6 | 44 | protected: |
paul@6 | 45 | _AccessMap _flexpages; |
paul@6 | 46 | std::mutex _lock; |
paul@6 | 47 | |
paul@6 | 48 | public: |
paul@6 | 49 | Flexpage *find(offset_t position); |
paul@6 | 50 | |
paul@6 | 51 | void insert(Flexpage *flexpage); |
paul@6 | 52 | |
paul@6 | 53 | bool remove(PageOwner *owner, Flexpage *flexpage); |
paul@6 | 54 | |
paul@72 | 55 | void purge(PageOwner *owner, Pages *pages); |
paul@6 | 56 | |
paul@72 | 57 | void flush_all(offset_t start, offset_t size, PageOwner *owner, Pages *pages); |
paul@6 | 58 | }; |
paul@6 | 59 | |
paul@6 | 60 | // vim: tabstop=4 expandtab shiftwidth=4 |