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)
25 void MutexObserver::serialize(std::stringstream& stream) const
27 auto* owner = get_mutex()->get_owner();
28 stream << (short)type_ << ' ' << (uintptr_t)get_mutex() << ' ' << (owner != nullptr ? owner->get_pid() : -1);
31 bool MutexObserver::is_enabled()
33 // Only wait can be disabled
34 return type_ != mc::Transition::Type::MUTEX_WAIT || mutex_->get_owner() == get_issuer();
39 } // namespace simgrid