Skip to content

Commit

Permalink
make Barrier constructor private and apply PR suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
LoreMoretti committed Feb 19, 2024
1 parent 2758fcc commit f882832
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
11 changes: 8 additions & 3 deletions src/System/include/BipedalLocomotion/System/Barrier.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Barrier> create(const std::size_t counter);

/**
* Blocks this thread at the phase synchronization point until its phase completion step is run
Expand All @@ -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
Expand Down
10 changes: 8 additions & 2 deletions src/System/src/Barrier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
* distributed under the terms of the BSD-3-Clause license.
*/

#include "BipedalLocomotion/TextLogging/Logger.h"
#include <memory>
#include <mutex>

#include <BipedalLocomotion/System/Barrier.h>
#include <BipedalLocomotion/TextLogging/Logger.h>

using namespace BipedalLocomotion::System;

Expand All @@ -19,6 +20,11 @@ Barrier::Barrier(const std::size_t counter)
{
}

std::shared_ptr<Barrier> Barrier::create(const std::size_t counter)
{
return std::shared_ptr<Barrier>(new Barrier(counter));
}

void Barrier::wait()
{
constexpr auto logPrefix = "[Barrier::wait]";
Expand All @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion src/System/tests/AdvanceableRunnerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ TEST_CASE("Test Block")
SECTION("With synchronization")
{
constexpr std::size_t numberOfRunners = 2;
auto barrier = std::make_shared<Barrier>(numberOfRunners);
auto barrier = Barrier::create(numberOfRunners);

// run the block
auto thread0 = runner0.run(barrier);
Expand Down

0 comments on commit f882832

Please sign in to comment.