X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/40334ce6fe520b2fa7d1e240716e4f34a5fdc74e..740d50812a81c59013f22888ab313da5a8113227:/src/mc/PageStore.hpp diff --git a/src/mc/PageStore.hpp b/src/mc/PageStore.hpp index 3491f587e0..8ed78ad023 100644 --- a/src/mc/PageStore.hpp +++ b/src/mc/PageStore.hpp @@ -4,24 +4,19 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -#include +#ifndef SIMGRID_MC_PAGESTORE_HPP +#define SIMGRID_MC_PAGESTORE_HPP -#ifdef __cplusplus +#include #include -#include -#include -#include -#include -#endif - -#include +#include +#include -#include "mc_mmu.h" -#include "mc_forward.h" +#include -#ifndef MC_PAGE_STORE_H -#define MC_PAGE_STORE_H +#include "src/mc/mc_mmu.h" +#include "src/mc/mc_forward.hpp" namespace simgrid { namespace mc { @@ -80,51 +75,37 @@ namespace mc { */ class PageStore { public: // Types -#ifdef MC_PAGE_STORE_MD4 - typedef boost::array hash_type; -#else - typedef uint64_t hash_type; -#endif + typedef std::uint64_t hash_type; private: // Types -#ifdef MC_PAGE_STORE_MD4 - // We are using a secure hash to identify a page. - // We assume there will not be any collision: we need to map a hash - // to a single page index. - typedef boost::unordered_map pages_map_type; -#else // We are using a cheap hash to index a page. // We should expect collision and we need to associate multiple page indices // to the same hash. - typedef boost::unordered_set page_set_type; - typedef boost::unordered_map pages_map_type; -#endif + typedef std::unordered_set page_set_type; + typedef std::unordered_map pages_map_type; private: // Fields: - /** First page - * - * mc_page_store_get_page expects that this is the first field. - * */ + /** First page */ void* memory_; /** Number of available pages in virtual memory */ - size_t capacity_; + std::size_t capacity_; /** Top of the used pages (index of the next available page) */ - size_t top_index_; + std::size_t top_index_; /** Page reference count */ - std::vector page_counts_; + std::vector page_counts_; /** Index of available pages before the top */ - std::vector free_pages_; + std::vector free_pages_; /** Index from page hash to page index */ pages_map_type hash_index_; private: // Methods - void resize(size_t size); - size_t alloc_page(); - void remove_page(size_t pageno); + void resize(std::size_t size); + std::size_t alloc_page(); + void remove_page(std::size_t pageno); public: // Constructors PageStore(PageStore const&) = delete; PageStore& operator=(PageStore const&) = delete; - explicit PageStore(size_t size); + explicit PageStore(std::size_t size); ~PageStore(); public: // Methods @@ -138,7 +119,7 @@ public: // Methods * it is added to the `free_pages_` list and removed from the `hash_index_`. * * */ - void unref_page(size_t pageno); + void unref_page(std::size_t pageno); /** @brief Increment the refcount for a given page * @@ -153,60 +134,63 @@ public: // Methods void ref_page(size_t pageno); /** @brief Store a page in the page store */ - size_t store_page(void* page); + std::size_t store_page(void* page); /** @brief Get a page from its page number * * @param Number of the memory page in the store * @return Start of the page */ - const void* get_page(size_t pageno) const; + const void* get_page(std::size_t pageno) const; public: // Debug/test methods /** @brief Get the number of references for a page */ - size_t get_ref(size_t pageno); + std::size_t get_ref(std::size_t pageno); /** @brief Get the number of used pages */ - size_t size(); + std::size_t size(); /** @brief Get the capacity of the page store * * The capacity is expanded by a system call (mremap). * */ - size_t capacity(); + std::size_t capacity(); }; inline __attribute__((always_inline)) -void PageStore::unref_page(size_t pageno) { - if ((--this->page_counts_[pageno]) == 0) { +void PageStore::unref_page(std::size_t pageno) { + if ((--this->page_counts_[pageno]) == 0) this->remove_page(pageno); - } } inline __attribute__((always_inline)) -void PageStore::ref_page(size_t pageno) { +void PageStore::ref_page(size_t pageno) +{ ++this->page_counts_[pageno]; } inline __attribute__((always_inline)) -const void* PageStore::get_page(size_t pageno) const { +const void* PageStore::get_page(std::size_t pageno) const +{ return mc_page_from_number(this->memory_, pageno); } inline __attribute__((always_inline)) -size_t PageStore::get_ref(size_t pageno) { +std::size_t PageStore::get_ref(std::size_t pageno) +{ return this->page_counts_[pageno]; } inline __attribute__((always_inline)) -size_t PageStore::size() { +std::size_t PageStore::size() { return this->top_index_ - this->free_pages_.size(); } inline __attribute__((always_inline)) -size_t PageStore::capacity() { +std::size_t PageStore::capacity() +{ return this->capacity_; }