From d28f1e9cfe50db12b47d07bf22d4dd9387ef963b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Widera?= Date: Tue, 12 Dec 2023 08:14:23 +0100 Subject: [PATCH] fix modulo zero Modulo zero is not allowed and results into an arithmetic error. --- redGrapes/memory/allocator.cpp | 2 +- redGrapes/redGrapes.cpp | 5 +++++ redGrapes/redGrapes.hpp | 6 +++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/redGrapes/memory/allocator.cpp b/redGrapes/memory/allocator.cpp index 5a982283..7c256096 100644 --- a/redGrapes/memory/allocator.cpp +++ b/redGrapes/memory/allocator.cpp @@ -15,7 +15,7 @@ Allocator::Allocator() Allocator::Allocator( dispatch::thread::WorkerId worker_id ) : worker_id( - worker_id % SingletonContext::get().n_workers + worker_id % SingletonContext::get().get_num_workers() ) {} diff --git a/redGrapes/redGrapes.cpp b/redGrapes/redGrapes.cpp index 53a3aad3..7f542066 100644 --- a/redGrapes/redGrapes.cpp +++ b/redGrapes/redGrapes.cpp @@ -44,6 +44,11 @@ Context::~Context() } +uint32_t Context::get_num_workers() const +{ + return n_workers == 0 ? 1 : n_workers; +} + std::shared_ptr Context::current_task_space() const { if( current_task ) diff --git a/redGrapes/redGrapes.hpp b/redGrapes/redGrapes.hpp index 38c57eb9..18c57e08 100644 --- a/redGrapes/redGrapes.hpp +++ b/redGrapes/redGrapes.hpp @@ -61,6 +61,8 @@ struct Context void execute_task( Task & task ); + uint32_t get_num_workers() const; + /*! create a new task, as child of the currently running task (if there is one) * * @param f callable that takes "proprty-building" objects as args @@ -83,7 +85,6 @@ struct Context static thread_local scheduler::WakerId current_waker_id; static thread_local std::shared_ptr< dispatch::thread::WorkerThread > current_worker; - unsigned n_workers; static thread_local unsigned current_arena; HwlocContext hwloc_ctx; std::shared_ptr< dispatch::thread::WorkerPool > worker_pool; @@ -94,6 +95,9 @@ struct Context #if REDGRAPES_ENABLE_TRACE std::shared_ptr< perfetto::TracingSession > tracing_session; #endif + + private: + unsigned n_workers; };