Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Try to tell sonar that the mutex_ cannot be null in is_enabled()
[simgrid.git] / src / kernel / actor / MutexObserver.cpp
1 /* Copyright (c) 2019-2022. The SimGrid Team. All rights reserved.          */
2
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. */
5
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"
11
12 #include <sstream>
13
14 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(obs_mutex, mc_observer, "Logging specific to mutex simcalls observation");
15
16 namespace simgrid {
17 namespace kernel {
18 namespace actor {
19
20 MutexObserver::MutexObserver(ActorImpl* actor, mc::Transition::Type type, activity::MutexImpl* mutex)
21     : SimcallObserver(actor), type_(type), mutex_(mutex)
22 {
23   xbt_assert(mutex_);
24 }
25
26 void MutexObserver::serialize(std::stringstream& stream) const
27 {
28   auto* owner = get_mutex()->get_owner();
29   stream << (short)type_ << ' ' << get_mutex()->get_id() << ' ' << (owner != nullptr ? owner->get_pid() : -1);
30 }
31
32 bool MutexObserver::is_enabled()
33 {
34   // Only wait can be disabled
35   return type_ != mc::Transition::Type::MUTEX_WAIT || mutex_->get_owner() == get_issuer();
36 }
37
38 } // namespace actor
39 } // namespace kernel
40 } // namespace simgrid