Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Rewrite without delegated constructor.
[simgrid.git] / src / mc / PageStore.hpp
index 36c90d0..da9d527 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2015. The SimGrid Team.
+/* Copyright (c) 2015-2018. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
 #include <unordered_map>
 #include <unordered_set>
 
-#include <xbt/base.h>
+#include "xbt/base.h"
 
-#include "mc_mmu.h"
-#include "mc_forward.hpp"
+#include "src/mc/mc_forward.hpp"
+#include "src/mc/mc_mmu.hpp"
 
 namespace simgrid {
 namespace mc {
 
 /** @brief Storage for snapshot memory pages
  *
- * The first (lower) layer of the per-page snapshot mechanism is a page
- * store: it's responsibility is to store immutable shareable
- * reference-counted memory pages independently of the snapshoting
- * logic. Snapshot management and representation, soft-dirty tracking is
- * handled to an higher layer. READMORE
+ * The first (lower) layer of the per-page snapshot mechanism is a page store:
+ * its responsibility is to store immutable sharable reference-counted memory
+ * pages independently of the snapshotting logic. Snapshot management and
+ * representation is handled to an higher layer. READMORE
  *
  * Data structure:
  *
@@ -76,14 +75,16 @@ namespace mc {
 class PageStore {
 public: // Types
   typedef std::uint64_t hash_type;
-private: // Types
+
+private:
+  // Types
   // 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 std::unordered_set<std::size_t> page_set_type;
   typedef std::unordered_map<hash_type, page_set_type> pages_map_type;
 
-private: // Fields:
+  // Fields:
   /** First page */
   void* memory_;
   /** Number of available pages in virtual memory */
@@ -97,23 +98,23 @@ private: // Fields:
   /** Index from page hash to page index */
   pages_map_type hash_index_;
 
-private: // Methods
+  // Methods
   void resize(std::size_t size);
   std::size_t alloc_page();
   void remove_page(std::size_t pageno);
 
-public: // Constructors
+public:
+  // Constructors
   PageStore(PageStore const&) = delete;
   PageStore& operator=(PageStore const&) = delete;
   explicit PageStore(std::size_t size);
   ~PageStore();
 
-public: // Methods
+  // Methods
 
   /** @brief Decrement the reference count for a given page
    *
-   * Decrement the reference count of this page. Used when a snapshot is
-   * destroyed.
+   * Decrement the reference count of this page. Used when a snapshot is destroyed.
    *
    * If the reference count reaches zero, the page is recycled:
    * it is added to the `free_pages_` list and removed from the `hash_index_`.
@@ -138,12 +139,12 @@ public: // Methods
 
   /** @brief Get a page from its page number
    *
-   *  @param Number of the memory page in the store
+   *  @param pageno Number of the memory page in the store
    *  @return Start of the page
    */
   const void* get_page(std::size_t pageno) const;
 
-public: // Debug/test methods
+  // Debug/test methods
 
   /** @brief Get the number of references for a page */
   std::size_t get_ref(std::size_t pageno);
@@ -159,37 +160,33 @@ public: // Debug/test methods
 
 };
 
-inline __attribute__((always_inline))
-void PageStore::unref_page(std::size_t pageno) {
+XBT_ALWAYS_INLINE 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)
+XBT_ALWAYS_INLINE void PageStore::ref_page(size_t pageno)
 {
   ++this->page_counts_[pageno];
 }
 
-inline __attribute__((always_inline))
-const void* PageStore::get_page(std::size_t pageno) const
+XBT_ALWAYS_INLINE const void* PageStore::get_page(std::size_t pageno) const
 {
-  return mc_page_from_number(this->memory_, pageno);
+  return (void*) simgrid::mc::mmu::join(pageno, (std::uintptr_t) this->memory_);
 }
 
-inline __attribute__((always_inline))
-std::size_t PageStore::get_ref(std::size_t pageno)
+XBT_ALWAYS_INLINE std::size_t PageStore::get_ref(std::size_t pageno)
 {
   return this->page_counts_[pageno];
 }
 
-inline __attribute__((always_inline))
-std::size_t PageStore::size() {
+XBT_ALWAYS_INLINE std::size_t PageStore::size()
+{
   return this->top_index_ - this->free_pages_.size();
 }
 
-inline __attribute__((always_inline))
-std::size_t PageStore::capacity()
+XBT_ALWAYS_INLINE std::size_t PageStore::capacity()
 {
   return this->capacity_;
 }