From f882832c061cd4c44a27dc11536c5546e4b11f8f Mon Sep 17 00:00:00 2001 From: Lorenzo Date: Mon, 19 Feb 2024 11:03:38 +0100 Subject: [PATCH] make Barrier constructor private and apply PR suggestions --- src/System/include/BipedalLocomotion/System/Barrier.h | 11 ++++++++--- src/System/src/Barrier.cpp | 10 ++++++++-- src/System/tests/AdvanceableRunnerTest.cpp | 2 +- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/System/include/BipedalLocomotion/System/Barrier.h b/src/System/include/BipedalLocomotion/System/Barrier.h index a2576e1970..2b73dc7615 100644 --- a/src/System/include/BipedalLocomotion/System/Barrier.h +++ b/src/System/include/BipedalLocomotion/System/Barrier.h @@ -24,10 +24,9 @@ class Barrier { public: /** - * Constructor. - * @param counter initial value of the expected counter + * Calls the constructor. It creates a new Barrier with the given counter. */ - explicit Barrier(const std::size_t counter); + static std::shared_ptr create(const std::size_t counter); /** * Blocks this thread at the phase synchronization point until its phase completion step is run @@ -40,6 +39,12 @@ class Barrier std::size_t m_initialCount; std::size_t m_count; std::size_t m_generation; + + /** + * Constructor. + * @param counter initial value of the expected counter + */ + explicit Barrier(const std::size_t counter); }; } // namespace System } // namespace BipedalLocomotion diff --git a/src/System/src/Barrier.cpp b/src/System/src/Barrier.cpp index fbdbc7f0ce..661d71b5d7 100644 --- a/src/System/src/Barrier.cpp +++ b/src/System/src/Barrier.cpp @@ -5,10 +5,11 @@ * distributed under the terms of the BSD-3-Clause license. */ -#include "BipedalLocomotion/TextLogging/Logger.h" +#include #include #include +#include using namespace BipedalLocomotion::System; @@ -19,6 +20,11 @@ Barrier::Barrier(const std::size_t counter) { } +std::shared_ptr Barrier::create(const std::size_t counter) +{ + return std::shared_ptr(new Barrier(counter)); +} + void Barrier::wait() { constexpr auto logPrefix = "[Barrier::wait]"; @@ -34,7 +40,7 @@ void Barrier::wait() m_count = m_initialCount; // notify the other threads - log()->info("{} All threads reached the barrier.", logPrefix); + log()->debug("{} All threads reached the barrier.", logPrefix); m_cond.notify_all(); } else { diff --git a/src/System/tests/AdvanceableRunnerTest.cpp b/src/System/tests/AdvanceableRunnerTest.cpp index a29ba38b82..6504cd6cd1 100644 --- a/src/System/tests/AdvanceableRunnerTest.cpp +++ b/src/System/tests/AdvanceableRunnerTest.cpp @@ -121,7 +121,7 @@ TEST_CASE("Test Block") SECTION("With synchronization") { constexpr std::size_t numberOfRunners = 2; - auto barrier = std::make_shared(numberOfRunners); + auto barrier = Barrier::create(numberOfRunners); // run the block auto thread0 = runner0.run(barrier);