X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/97e476dc536bfd9fada85509d1c1f93714d46a10..63d238ad4d74226fae3321cb5c128f03160dacb2:/src/kernel/actor/SynchroObserver.hpp diff --git a/src/kernel/actor/SynchroObserver.hpp b/src/kernel/actor/SynchroObserver.hpp index de283d1c08..b2bfd31fe8 100644 --- a/src/kernel/actor/SynchroObserver.hpp +++ b/src/kernel/actor/SynchroObserver.hpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2019-2022. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2019-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. */ @@ -7,18 +7,17 @@ #define SIMGRID_MC_MUTEX_OBSERVER_HPP #include "simgrid/forward.h" +#include "src/kernel/activity/ConditionVariableImpl.hpp" #include "src/kernel/activity/MutexImpl.hpp" #include "src/kernel/actor/ActorImpl.hpp" #include "src/kernel/actor/SimcallObserver.hpp" #include -namespace simgrid { -namespace kernel { -namespace actor { +namespace simgrid::kernel::actor { /* All the observers of Mutex transitions are very similar, so implement them all together in this class */ -class MutexObserver : public SimcallObserver { +class MutexObserver final : public SimcallObserver { mc::Transition::Type type_; activity::MutexImpl* const mutex_; @@ -26,13 +25,14 @@ public: MutexObserver(ActorImpl* actor, mc::Transition::Type type, activity::MutexImpl* mutex); void serialize(std::stringstream& stream) const override; + std::string to_string() const override; bool is_enabled() override; activity::MutexImpl* get_mutex() const { return mutex_; } }; /* This observer is used for SEM_LOCK and SEM_UNLOCK (only) */ -class SemaphoreObserver : public SimcallObserver { +class SemaphoreObserver final : public SimcallObserver { mc::Transition::Type type_; activity::SemaphoreImpl* const sem_; @@ -40,12 +40,13 @@ public: SemaphoreObserver(ActorImpl* actor, mc::Transition::Type type, activity::SemaphoreImpl* sem); void serialize(std::stringstream& stream) const override; + std::string to_string() const override; activity::SemaphoreImpl* get_sem() const { return sem_; } }; /* This observer is ued for SEM_WAIT, that is returning and needs the acquisition (in MC mode) */ -class SemaphoreAcquisitionObserver : public ResultingSimcall { +class SemaphoreAcquisitionObserver final : public ResultingSimcall { mc::Transition::Type type_; activity::SemAcquisitionImpl* const acquisition_; const double timeout_; @@ -55,13 +56,14 @@ public: double timeout = -1.0); void serialize(std::stringstream& stream) const override; + std::string to_string() const override; bool is_enabled() override; double get_timeout() const { return timeout_; } }; -/* This observer is ued for BARRIER_LOCK and BARRIER_WAIT. WAIT is returning and needs the acquisition */ -class BarrierObserver : public ResultingSimcall { +/* This observer is used for BARRIER_LOCK and BARRIER_WAIT. WAIT is returning and needs the acquisition */ +class BarrierObserver final : public ResultingSimcall { mc::Transition::Type type_; activity::BarrierImpl* const barrier_ = nullptr; activity::BarrierAcquisitionImpl* const acquisition_ = nullptr; @@ -73,13 +75,33 @@ public: double timeout = -1.0); void serialize(std::stringstream& stream) const override; + std::string to_string() const override; bool is_enabled() override; double get_timeout() const { return timeout_; } }; -} // namespace actor -} // namespace kernel -} // namespace simgrid +class ConditionVariableObserver final : public ResultingSimcall { + mc::Transition::Type type_; + activity::ConditionVariableImpl* const cond_; + activity::MutexImpl* const mutex_; + const double timeout_; + +public: + ConditionVariableObserver(ActorImpl* actor, activity::ConditionVariableImpl* cond, activity::MutexImpl* mutex, + double timeout = -1.0) + : ResultingSimcall(actor, false), cond_(cond), mutex_(mutex), timeout_(timeout) + { + xbt_assert(mutex != nullptr, "Cannot wait on a condition variable without a valid mutex"); + } + void serialize(std::stringstream& stream) const override; + std::string to_string() const override; + bool is_enabled() override; + activity::ConditionVariableImpl* get_cond() const { return cond_; } + activity::MutexImpl* get_mutex() const { return mutex_; } + double get_timeout() const { return timeout_; } +}; + +} // namespace simgrid::kernel::actor #endif