1 /* Copyright (c) 2019-2022. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #include "src/kernel/actor/MutexObserver.hpp"
7 #include "simgrid/s4u/Host.hpp"
8 #include "src/kernel/activity/MutexImpl.hpp"
9 #include "src/kernel/actor/ActorImpl.hpp"
10 #include "src/mc/mc_config.hpp"
14 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(obs_mutex, mc_observer, "Logging specific to mutex simcalls observation");
20 MutexObserver::MutexObserver(ActorImpl* actor, mc::Transition::Type type, activity::MutexImpl* mutex)
21 : SimcallObserver(actor), type_(type), mutex_(mutex)
26 void MutexObserver::serialize(std::stringstream& stream) const
28 auto* owner = get_mutex()->get_owner();
29 stream << (short)type_ << ' ' << get_mutex()->get_id() << ' ' << (owner != nullptr ? owner->get_pid() : -1);
32 bool MutexObserver::is_enabled()
34 // Only wait can be disabled
35 return type_ != mc::Transition::Type::MUTEX_WAIT || mutex_->get_owner() == get_issuer();
40 } // namespace simgrid