From 68d9a0c88dc296fae41b23528a1345b4534dc96a Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Tue, 9 Mar 2021 15:36:05 +0100 Subject: [PATCH] Merge oberver classes MutexTrylockSimcall and MutexLockSimcall. --- src/mc/checker/SimcallObserver.cpp | 20 +++----------------- src/mc/checker/SimcallObserver.hpp | 16 +++++----------- src/s4u/s4u_Mutex.cpp | 2 +- 3 files changed, 9 insertions(+), 29 deletions(-) diff --git a/src/mc/checker/SimcallObserver.cpp b/src/mc/checker/SimcallObserver.cpp index 5a384fd56c..3b7854c207 100644 --- a/src/mc/checker/SimcallObserver.cpp +++ b/src/mc/checker/SimcallObserver.cpp @@ -57,23 +57,9 @@ std::string MutexUnlockSimcall::dot_label() const return SimcallObserver::dot_label() + "Mutex UNLOCK"; } -std::string MutexTrylockSimcall::to_string(int time_considered) const -{ - std::string res = SimcallObserver::to_string(time_considered) + "Mutex TRYLOCK"; - res += "(locked = " + std::to_string(mutex_->is_locked()); - res += ", owner = " + std::to_string(mutex_->get_owner() ? mutex_->get_owner()->get_pid() : -1); - res += ", sleeping = n/a)"; - return res; -} - -std::string MutexTrylockSimcall::dot_label() const -{ - return SimcallObserver::dot_label() + "Mutex TRYLOCK"; -} - std::string MutexLockSimcall::to_string(int time_considered) const { - std::string res = SimcallObserver::to_string(time_considered) + "Mutex LOCK"; + std::string res = SimcallObserver::to_string(time_considered) + (blocking_ ? "Mutex LOCK" : "Mutex TRYLOCK"); res += "(locked = " + std::to_string(mutex_->is_locked()); res += ", owner = " + std::to_string(mutex_->get_owner() ? mutex_->get_owner()->get_pid() : -1); res += ", sleeping = n/a)"; @@ -82,12 +68,12 @@ std::string MutexLockSimcall::to_string(int time_considered) const std::string MutexLockSimcall::dot_label() const { - return SimcallObserver::dot_label() + "Mutex LOCK"; + return SimcallObserver::dot_label() + (blocking_ ? "Mutex LOCK" : "Mutex TRYLOCK"); } bool MutexLockSimcall::is_enabled() const { - return mutex_->get_owner() == nullptr || mutex_->get_owner() == get_issuer(); + return not blocking_ || mutex_->get_owner() == nullptr || mutex_->get_owner() == get_issuer(); } } // namespace mc } // namespace simgrid diff --git a/src/mc/checker/SimcallObserver.hpp b/src/mc/checker/SimcallObserver.hpp index 3ae882edb7..eee2c76555 100644 --- a/src/mc/checker/SimcallObserver.hpp +++ b/src/mc/checker/SimcallObserver.hpp @@ -74,21 +74,15 @@ public: std::string dot_label() const override; }; -class MutexTrylockSimcall : public SimcallObserver { - kernel::activity::MutexImpl* mutex_; - -public: - MutexTrylockSimcall(smx_actor_t actor, kernel::activity::MutexImpl* mutex) : SimcallObserver(actor), mutex_(mutex) {} - std::string to_string(int times_considered) const override; - std::string dot_label() const override; - kernel::activity::MutexImpl* get_mutex() const { return mutex_; } -}; - class MutexLockSimcall : public SimcallObserver { kernel::activity::MutexImpl* mutex_; + bool blocking_; public: - MutexLockSimcall(smx_actor_t actor, kernel::activity::MutexImpl* mutex) : SimcallObserver(actor), mutex_(mutex) {} + MutexLockSimcall(smx_actor_t actor, kernel::activity::MutexImpl* mutex, bool blocking = true) + : SimcallObserver(actor), mutex_(mutex), blocking_(blocking) + { + } bool is_enabled() const override; std::string to_string(int times_considered) const override; std::string dot_label() const override; diff --git a/src/s4u/s4u_Mutex.cpp b/src/s4u/s4u_Mutex.cpp index 8975cb7bae..e855283e86 100644 --- a/src/s4u/s4u_Mutex.cpp +++ b/src/s4u/s4u_Mutex.cpp @@ -41,7 +41,7 @@ void Mutex::unlock() bool Mutex::try_lock() { kernel::actor::ActorImpl* issuer = kernel::actor::ActorImpl::self(); - mc::MutexTrylockSimcall observer{issuer, pimpl_}; + mc::MutexLockSimcall observer{issuer, pimpl_, false}; return kernel::actor::simcall([&observer] { return observer.get_mutex()->try_lock(observer.get_issuer()); }, &observer); } -- 2.20.1