From c9e2bc227886f6470890ba76d3d849c138d50823 Mon Sep 17 00:00:00 2001 From: Victor Olin Date: Fri, 7 Apr 2023 20:40:01 +0200 Subject: [PATCH] Cleaned up include guards --- src/GC/include/cheap.h | 4 ++-- src/GC/include/event.hpp | 3 --- src/GC/include/heap.hpp | 7 ++----- src/GC/include/profiler.hpp | 1 + src/GC/lib/cheap.cpp | 4 ++-- src/GC/lib/event.cpp | 4 ---- src/GC/lib/heap.cpp | 41 ++++++++----------------------------- 7 files changed, 16 insertions(+), 48 deletions(-) diff --git a/src/GC/include/cheap.h b/src/GC/include/cheap.h index d2c649d..f4cd03c 100644 --- a/src/GC/include/cheap.h +++ b/src/GC/include/cheap.h @@ -7,9 +7,9 @@ extern "C" { #endif -// #define DEBUG +// #define WRAPPER_DEBUG -#ifdef DEBUG +#ifdef WRAPPER_DEBUG typedef struct cheap { void *obj; diff --git a/src/GC/include/event.hpp b/src/GC/include/event.hpp index 298ccab..d4d5e10 100644 --- a/src/GC/include/event.hpp +++ b/src/GC/include/event.hpp @@ -1,9 +1,6 @@ #pragma once #include -#include -#include -#include #include "chunk.hpp" diff --git a/src/GC/include/heap.hpp b/src/GC/include/heap.hpp index 365a838..36fa83b 100644 --- a/src/GC/include/heap.hpp +++ b/src/GC/include/heap.hpp @@ -1,8 +1,5 @@ #pragma once -#include -#include -#include #include #include @@ -11,7 +8,7 @@ #define HEAP_SIZE 2097152 //65536 #define FREE_THRESH (uint) 100000 -#define DEBUG +// #define HEAP_DEBUG namespace GC { @@ -89,7 +86,7 @@ namespace GC Heap(Heap const&) = delete; Heap& operator=(Heap const&) = delete; -#ifdef DEBUG +#ifdef HEAP_DEBUG void collect(CollectOption flags); // conditional collection void check_init(); // print dummy things void print_contents(); // print dummy things diff --git a/src/GC/include/profiler.hpp b/src/GC/include/profiler.hpp index ccdf463..4864dd6 100644 --- a/src/GC/include/profiler.hpp +++ b/src/GC/include/profiler.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include "chunk.hpp" diff --git a/src/GC/lib/cheap.cpp b/src/GC/lib/cheap.cpp index 29a0b10..f6c24a9 100644 --- a/src/GC/lib/cheap.cpp +++ b/src/GC/lib/cheap.cpp @@ -1,10 +1,10 @@ #include -#include +#include #include "heap.hpp" #include "cheap.h" -#ifndef DEBUG +#ifndef WRAPPER_DEBUG struct cheap { void *obj; diff --git a/src/GC/lib/event.cpp b/src/GC/lib/event.cpp index 185c613..89a2a71 100644 --- a/src/GC/lib/event.cpp +++ b/src/GC/lib/event.cpp @@ -1,7 +1,3 @@ -// #include -// #include -// #include - #include "chunk.hpp" #include "event.hpp" diff --git a/src/GC/lib/heap.cpp b/src/GC/lib/heap.cpp index 579f421..61319f0 100644 --- a/src/GC/lib/heap.cpp +++ b/src/GC/lib/heap.cpp @@ -1,9 +1,4 @@ -#include -#include -#include -#include #include -#include #include #include #include @@ -83,7 +78,8 @@ namespace GC { heap.collect(); // If memory is not enough after collect, crash with OOM error - throw std::runtime_error(std::string("Error: Heap out of memory")); + if (heap.m_size + size > HEAP_SIZE) + throw std::runtime_error(std::string("Error: Heap out of memory")); } // If a chunk was recycled, return the old chunk address @@ -159,25 +155,6 @@ namespace GC return nullptr; } - /** - * Advances an iterator and returns an element - * at position `n`. - * - * @param list The list to retrieve an element from. - * - * @param n The position to retrieve an element at. - * - * @returns The pointer to the chunk at position n in list. - */ - // Chunk *Heap::get_at(std::vector &list, size_t n) - // { - // auto iter = list.begin(); - // if (!n) - // return *iter; - // std::advance(iter, n); - // return *iter; - // } - /** * Returns a bool whether the profiler is enabled * or not. @@ -414,7 +391,13 @@ namespace GC } } -#ifdef DEBUG + void Heap::set_profiler(bool mode) + { + Heap &heap = Heap::the(); + heap.m_profiler_enable = mode; + } + +#ifdef HEAP_DEBUG /** * Prints the result of Heap::init() and a dummy value * for the current stack frame for reference. @@ -565,12 +548,6 @@ namespace GC } } - void Heap::set_profiler(bool mode) - { - Heap &heap = Heap::the(); - heap.m_profiler_enable = mode; - } - void Heap::print_allocated_chunks(Heap *heap) { cout << "--- Allocated Chunks ---\n" << endl; for (auto chunk : heap->m_allocated_chunks) {