Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines for 2023.
[simgrid.git] / src / kernel / actor / SimcallObserver.cpp
1 /* Copyright (c) 2019-2023. 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/SimcallObserver.hpp"
7 #include "simgrid/s4u/Host.hpp"
8 #include "src/kernel/activity/CommImpl.hpp"
9 #include "src/kernel/activity/MailboxImpl.hpp"
10 #include "src/kernel/actor/ActorImpl.hpp"
11 #include "src/mc/mc_config.hpp"
12
13 #include <sstream>
14
15 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_observer, mc, "Logging specific to MC simcall observation");
16
17 namespace simgrid::kernel::actor {
18
19 void RandomSimcall::serialize(std::stringstream& stream) const
20 {
21   stream << (short)mc::Transition::Type::RANDOM << ' ';
22   stream << min_ << ' ' << max_;
23 }
24 std::string RandomSimcall::to_string() const
25 {
26   return "Random(min:" + std::to_string(min_) + " max:" + std::to_string(max_) + ")";
27 }
28
29 void RandomSimcall::prepare(int times_considered)
30 {
31   next_value_ = min_ + times_considered;
32   XBT_DEBUG("MC_RANDOM(%d, %d) will return %d after %d times", min_, max_, next_value_, times_considered);
33 }
34
35 int RandomSimcall::get_max_consider() const
36 {
37   return max_ - min_ + 1;
38 }
39
40 bool ConditionWaitSimcall::is_enabled()
41 {
42   if (static bool warned = false; not warned) {
43     XBT_INFO("Using condition variables in model-checked code is still experimental. Use at your own risk");
44     warned = true;
45   }
46   return true;
47 }
48 void ConditionWaitSimcall::serialize(std::stringstream& stream) const
49 {
50   THROW_UNIMPLEMENTED;
51 }
52 std::string ConditionWaitSimcall::to_string() const
53 {
54   THROW_UNIMPLEMENTED;
55 }
56
57 ActorJoinSimcall::ActorJoinSimcall(ActorImpl* actor, ActorImpl* other, double timeout)
58     : SimcallObserver(actor), other_(s4u::ActorPtr(other->get_iface())), timeout_(timeout)
59 {
60 }
61 bool ActorJoinSimcall::is_enabled()
62 {
63   return other_->get_impl()->wannadie();
64 }
65 void ActorJoinSimcall::serialize(std::stringstream& stream) const
66 {
67   stream << (short)mc::Transition::Type::ACTOR_JOIN << ' ';
68   stream << other_->get_pid() << ' ' << (timeout_ > 0);
69 }
70 std::string ActorJoinSimcall::to_string() const
71 {
72   return "ActorJoin(pid:" + std::to_string(other_->get_pid()) + ")";
73 }
74
75 void ObjectAccessSimcallObserver::serialize(std::stringstream& stream) const
76 {
77   stream << (short)mc::Transition::Type::OBJECT_ACCESS << ' ';
78   stream << object_ << ' ' << get_owner()->get_pid();
79 }
80 std::string ObjectAccessSimcallObserver::to_string() const
81 {
82   return "ObjectAccess(obj:" + ptr_to_id<ObjectAccessSimcallItem const>(object_) +
83          " owner:" + std::to_string(get_owner()->get_pid()) + ")";
84 }
85 bool ObjectAccessSimcallObserver::is_visible() const
86 {
87   return get_owner() != get_issuer();
88 }
89 ActorImpl* ObjectAccessSimcallObserver::get_owner() const
90 {
91   return object_->simcall_owner_;
92 }
93
94 } // namespace simgrid::kernel::actor