From c653850408238939b9bfcc9658a3e8348bee9407 Mon Sep 17 00:00:00 2001 From: FritzFlorian Date: Tue, 2 Apr 2019 11:21:20 +0200 Subject: [PATCH] Move error handling into own file. The current solution is not clean, but allows us to change error handling later on without missing any point in the programm where we would want to use it. --- lib/pls/CMakeLists.txt | 2 +- lib/pls/include/pls/internal/base/aligned_stack.h | 4 +++- lib/pls/include/pls/internal/base/error_handling.h | 10 ++++++++++ lib/pls/src/internal/scheduling/scheduler.cpp | 3 ++- 4 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 lib/pls/include/pls/internal/base/error_handling.h diff --git a/lib/pls/CMakeLists.txt b/lib/pls/CMakeLists.txt index ff6fe7e..83d7e1a 100644 --- a/lib/pls/CMakeLists.txt +++ b/lib/pls/CMakeLists.txt @@ -14,7 +14,7 @@ add_library(pls STATIC src/internal/scheduling/run_on_n_threads_task.cpp include/pls/internal/scheduling/run_on_n_threads_task.h src/internal/scheduling/fork_join_task.cpp include/pls/internal/scheduling/fork_join_task.h src/internal/base/deque.cpp include/pls/internal/base/deque.h - src/algorithms/invoke_parallel.cpp include/pls/algorithms/invoke_parallel.h) + src/algorithms/invoke_parallel.cpp include/pls/algorithms/invoke_parallel.h include/pls/internal/base/error_handling.h) # Add everything in `./include` to be in the include path of this project target_include_directories(pls diff --git a/lib/pls/include/pls/internal/base/aligned_stack.h b/lib/pls/include/pls/internal/base/aligned_stack.h index 8480fe1..c463232 100644 --- a/lib/pls/include/pls/internal/base/aligned_stack.h +++ b/lib/pls/include/pls/internal/base/aligned_stack.h @@ -5,6 +5,8 @@ #include #include +#include "pls/internal/base/error_handling.h" + namespace pls { namespace internal { namespace base { @@ -41,7 +43,7 @@ namespace pls { // Move head to next aligned position after new object head_ = next_alignment(head_ + sizeof(T)); if (head_ >= memory_end_) { - exit(1); // TODO: Exception Handling + PLS_ERROR("Tried to allocate object on alligned_stack without sufficient memory!"); } return result; diff --git a/lib/pls/include/pls/internal/base/error_handling.h b/lib/pls/include/pls/internal/base/error_handling.h new file mode 100644 index 0000000..d405dde --- /dev/null +++ b/lib/pls/include/pls/internal/base/error_handling.h @@ -0,0 +1,10 @@ + +#ifndef PLS_ERROR_HANDLING_H +#define PLS_ERROR_HANDLING_H + +#include + +// TODO: Figure out proper exception handling +#define PLS_ERROR(msg) std::cout << msg << std::endl; exit(1); + +#endif //PLS_ERROR_HANDLING_H diff --git a/lib/pls/src/internal/scheduling/scheduler.cpp b/lib/pls/src/internal/scheduling/scheduler.cpp index 8e55147..b32907f 100644 --- a/lib/pls/src/internal/scheduling/scheduler.cpp +++ b/lib/pls/src/internal/scheduling/scheduler.cpp @@ -1,4 +1,5 @@ #include "pls/internal/scheduling/scheduler.h" +#include "pls/internal/base/error_handling.h" namespace pls { namespace internal { @@ -9,7 +10,7 @@ namespace pls { sync_barrier_{num_threads + 1}, terminated_{false} { if (num_threads > MAX_THREADS) { - exit(1); // TODO: Exception Handling + PLS_ERROR("Tried to create scheduler with more OS threads than pre-allocated memory."); } for (unsigned int i = 0; i < num_threads; i++) { -- libgit2 0.26.0