Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
294fc3a64536e886574db38493c8e0b24fe2d0a9
[simgrid.git] / src / kernel / actor / SimcallObserver.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/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
25 void RandomSimcall::prepare(int times_considered)
26 {
27   next_value_ = min_ + times_considered;
28   XBT_DEBUG("MC_RANDOM(%d, %d) will return %d after %d times", min_, max_, next_value_, times_considered);
29 }
30
31 int RandomSimcall::get_max_consider() const
32 {
33   return max_ - min_ + 1;
34 }
35
36 bool ConditionWaitSimcall::is_enabled()
37 {
38   if (static bool warned = false; not warned) {
39     XBT_INFO("Using condition variables in model-checked code is still experimental. Use at your own risk");
40     warned = true;
41   }
42   return true;
43 }
44 void ConditionWaitSimcall::serialize(std::stringstream& stream) const
45 {
46   THROW_UNIMPLEMENTED;
47 }
48
49 ActorJoinSimcall::ActorJoinSimcall(ActorImpl* actor, ActorImpl* other, double timeout)
50     : SimcallObserver(actor), other_(s4u::ActorPtr(other->get_iface())), timeout_(timeout)
51 {
52 }
53 bool ActorJoinSimcall::is_enabled()
54 {
55   return other_->get_impl()->wannadie();
56 }
57 void ActorJoinSimcall::serialize(std::stringstream& stream) const
58 {
59   stream << (short)mc::Transition::Type::ACTOR_JOIN << ' ';
60   stream << other_->get_pid() << ' ' << static_cast<bool>(timeout_ > 0);
61 }
62 } // namespace simgrid::kernel::actor