/* A thread pool (C++ version). */
-/* Copyright (c) 2004-2020 The SimGrid Team. All rights reserved. */
+/* Copyright (c) 2004-2022 The SimGrid Team. All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
#define XBT_PARMAP_HPP
#include "src/internal_config.h" // HAVE_FUTEX_H
+#include "src/kernel/EngineImpl.hpp"
#include "src/kernel/context/Context.hpp"
-#include "src/simix/smx_private.hpp" /* simix_global */
#include <boost/optional.hpp>
#include <condition_variable>
/** @brief Main function of a worker thread */
template <typename T> void Parmap<T>::worker_main(ThreadData* data)
{
+ auto engine = simgrid::kernel::EngineImpl::get_instance();
Parmap<T>& parmap = data->parmap;
unsigned round = 0;
- kernel::context::Context* context = simix_global->context_factory->create_context(std::function<void()>(), nullptr);
+ kernel::context::Context* context = engine->get_context_factory()->create_context(std::function<void()>(), nullptr);
kernel::context::Context::set_current(context);
XBT_CDEBUG(xbt_parmap, "New worker thread created");
template <typename T> void Parmap<T>::PosixSynchro::master_wait()
{
std::unique_lock<std::mutex> lk(done_mutex);
- while (this->parmap.thread_counter < this->parmap.num_workers) {
- /* wait for all workers to be ready */
- done_cond.wait(lk);
- }
+ /* wait for all workers to be ready */
+ done_cond.wait(lk, [this]() { return this->parmap.thread_counter >= this->parmap.num_workers; });
}
template <typename T> void Parmap<T>::PosixSynchro::worker_signal()
{
std::unique_lock<std::mutex> lk(ready_mutex);
/* wait for more work */
- while (this->parmap.work_round != round) {
- ready_cond.wait(lk);
- }
+ ready_cond.wait(lk, [this, round]() { return this->parmap.work_round == round; });
}
#if HAVE_FUTEX_H