Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/ServerPrivate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -198,16 +198,22 @@ bool ServerPrivate::Run(const uint64_t _iterations,
}
else
{
if (!this->workerPool.has_value())
{
// Initialize the workerpool if we do have multiple simulation runners and
// it hasn't been initialized before
this->workerPool.emplace(2);
}
for (std::unique_ptr<SimulationRunner> &runner : this->simRunners)
{
this->workerPool.AddWork([&runner, &_iterations] ()
this->workerPool->AddWork([&runner, &_iterations] ()
{
runner->Run(_iterations);
});
}

// Wait for the runner to complete.
result = this->workerPool.WaitForResults();
result = this->workerPool->WaitForResults();
}

// See comments ServerPrivate::Stop() for why we lock this mutex here.
Expand Down
5 changes: 4 additions & 1 deletion src/ServerPrivate.hh
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,10 @@ namespace gz
const gz::msgs::ServerControl &_req, msgs::Boolean &_res);

/// \brief A pool of worker threads.
public: common::WorkerPool workerPool{2};
/// \note We use optional here since most of the time, there will be a
/// single simulation runner and a workerpool is not needed. We will
/// initialize the workerpool as necessary later on.
public: std::optional<common::WorkerPool> workerPool;

/// \brief All the simulation runners.
public: std::vector<std::unique_ptr<SimulationRunner>> simRunners;
Expand Down
4 changes: 0 additions & 4 deletions src/SimulationRunner.hh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
#include <sdf/World.hh>

#include <gz/common/Event.hh>
#include <gz/common/WorkerPool.hh>
#include <gz/math/Stopwatch.hh>
#include <gz/transport/Node.hh>

Expand Down Expand Up @@ -433,9 +432,6 @@ namespace gz
/// \brief Manager of distributing/receiving network work.
private: std::unique_ptr<NetworkManager> networkMgr{nullptr};

/// \brief A pool of worker threads.
private: common::WorkerPool workerPool{2};

/// \brief Wall time of the previous update.
private: std::chrono::steady_clock::time_point prevUpdateRealTime;

Expand Down
Loading