X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/c1de1bfb13b52bcf4ded13be31ab44b4211cfc13..5ed37babb2fa9097abe82df299c0aa259ed84d5a:/src/kernel/activity/ConditionVariableImpl.cpp?ds=sidebyside diff --git a/src/kernel/activity/ConditionVariableImpl.cpp b/src/kernel/activity/ConditionVariableImpl.cpp index 418325608a..2315ebe59e 100644 --- a/src/kernel/activity/ConditionVariableImpl.cpp +++ b/src/kernel/activity/ConditionVariableImpl.cpp @@ -1,35 +1,31 @@ -/* Copyright (c) 2007-2021. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2007-2023. 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. */ #include "src/kernel/activity/ConditionVariableImpl.hpp" -#include "simgrid/Exception.hpp" #include "src/kernel/activity/MutexImpl.hpp" -#include "src/kernel/activity/SynchroRaw.hpp" -#include "src/mc/checker/SimcallObserver.hpp" +#include "src/kernel/activity/Synchro.hpp" +#include "src/kernel/actor/SimcallObserver.hpp" #include // std::isfinite -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_condition, simix_synchro, "Condition variables"); +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_condition, ker_synchro, "Condition variables kernel-space implementation"); /********************************* Condition **********************************/ -namespace simgrid { -namespace kernel { -namespace activity { +namespace simgrid::kernel::activity { /** * @brief Signalizes a condition. * - * Signalizes a condition and wakes up a sleeping process. - * If there are no process sleeping, no action is done. + * Signalizes a condition and wakes up a sleeping actor. + * If there are no actor sleeping, no action is done. */ void ConditionVariableImpl::signal() { XBT_DEBUG("Signal condition %p", this); - /* If there are processes waiting for the condition choose one and try - to make it acquire the mutex */ + /* If there are actors waiting for the condition choose one and try to make it acquire the mutex */ if (not sleeping_.empty()) { auto& proc = sleeping_.front(); sleeping_.pop_front(); @@ -38,11 +34,10 @@ void ConditionVariableImpl::signal() proc.waiting_synchro_ = nullptr; /* Now transform the cond wait simcall into a mutex lock one */ - smx_simcall_t simcall = &proc.simcall_; - // FIXME? using here the MC observer to solve a problem not related to MC - const auto* observer = dynamic_cast(simcall->observer_); + actor::Simcall* simcall = &proc.simcall_; + const auto* observer = dynamic_cast(simcall->observer_); xbt_assert(observer != nullptr); - observer->get_mutex()->lock(simcall->issuer_); + observer->get_mutex()->lock_async(simcall->issuer_)->wait_for(simcall->issuer_, -1); } XBT_OUT(); } @@ -50,8 +45,8 @@ void ConditionVariableImpl::signal() /** * @brief Broadcasts a condition. * - * Signal ALL processes waiting on a condition. - * If there are no process waiting, no action is done. + * Signal ALL actors waiting on a condition. + * If there are no actor waiting, no action is done. */ void ConditionVariableImpl::broadcast() { @@ -62,11 +57,10 @@ void ConditionVariableImpl::broadcast() signal(); } -void ConditionVariableImpl::wait(smx_mutex_t mutex, double timeout, actor::ActorImpl* issuer) +void ConditionVariableImpl::wait(MutexImpl* mutex, double timeout, actor::ActorImpl* issuer) { XBT_DEBUG("Wait condition %p", this); xbt_assert(std::isfinite(timeout), "timeout is not finite!"); - simix::marshal(issuer->simcall_.result_, false); // default result, will be set to 'true' on timeout /* If there is a mutex unlock it */ if (mutex != nullptr) { @@ -77,9 +71,11 @@ void ConditionVariableImpl::wait(smx_mutex_t mutex, double timeout, actor::Actor mutex->unlock(issuer); } - RawImplPtr synchro(new RawImpl([this, issuer]() { + SynchroImplPtr synchro(new SynchroImpl([this, issuer]() { this->remove_sleeping_actor(*issuer); - simix::marshal(issuer->simcall_.result_, true); + auto* observer = dynamic_cast(issuer->simcall_.observer_); + xbt_assert(observer != nullptr); + observer->set_result(true); })); synchro->set_host(issuer->get_host()).set_timeout(timeout).start(); synchro->register_simcall(&issuer->simcall_); @@ -87,12 +83,12 @@ void ConditionVariableImpl::wait(smx_mutex_t mutex, double timeout, actor::Actor } // boost::intrusive_ptr support: -void intrusive_ptr_add_ref(simgrid::kernel::activity::ConditionVariableImpl* cond) +void intrusive_ptr_add_ref(ConditionVariableImpl* cond) { cond->refcount_.fetch_add(1, std::memory_order_relaxed); } -void intrusive_ptr_release(simgrid::kernel::activity::ConditionVariableImpl* cond) +void intrusive_ptr_release(ConditionVariableImpl* cond) { if (cond->refcount_.fetch_sub(1, std::memory_order_release) == 1) { std::atomic_thread_fence(std::memory_order_acquire); @@ -100,6 +96,4 @@ void intrusive_ptr_release(simgrid::kernel::activity::ConditionVariableImpl* con delete cond; } } -} // namespace activity -} // namespace kernel -} // namespace simgrid +} // namespace simgrid::kernel::activity