Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'battery-get-name' into 'master'
[simgrid.git] / src / mc / transition / TransitionActor.cpp
1 /* Copyright (c) 2015-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/mc/transition/TransitionActor.hpp"
7 #include "simgrid/config.h"
8 #include "xbt/asserts.h"
9 #include "xbt/string.hpp"
10
11 #include <sstream>
12
13 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_trans_actorlifecycle, mc_transition,
14                                 "Logging specific to MC transitions about actors' lifecycle: joining, ending");
15
16 namespace simgrid::mc {
17
18 ActorJoinTransition::ActorJoinTransition(aid_t issuer, int times_considered, std::stringstream& stream)
19     : Transition(Type::ACTOR_JOIN, issuer, times_considered)
20 {
21   xbt_assert(stream >> target_ >> timeout_);
22   XBT_DEBUG("ActorJoinTransition target:%ld, %s ", target_, (timeout_ ? "timeout" : "no-timeout"));
23 }
24 std::string ActorJoinTransition::to_string(bool verbose) const
25 {
26   return xbt::string_printf("ActorJoin(target %ld, %s)", target_, (timeout_ ? "timeout" : "no timeout"));
27 }
28 bool ActorJoinTransition::depends(const Transition* other) const
29 {
30   // Actions executed by the same actor are always dependent
31   if (other->aid_ == aid_)
32     return true;
33
34   // Joining is dependent with any transition whose
35   // actor is that of the `other` action. , Join i
36   if (other->aid_ == target_) {
37     return true;
38   }
39
40   // Actions executed by the same actor are always dependent
41   if (other->aid_ == aid_)
42     return true;
43
44   // Otherwise, joining is indep with any other transitions:
45   // - It is only enabled once the target ends, and after this point it's enabled no matter what
46   // - Other joins don't affect it, and it does not impact on the enabledness of any other transition
47   return false;
48 }
49
50 bool ActorJoinTransition::reversible_race(const Transition* other) const
51 {
52   switch (type_) {
53     case Type::ACTOR_JOIN:
54       // ActorJoin races with another event iff its target `T` is the same as
55       // the actor executing the other transition. Clearly, then, we could not join
56       // on that actor `T` and then run a transition by `T`, so no race is reversible
57       return false;
58     default:
59       xbt_die("Unexpected transition type %s", to_c_str(type_));
60   }
61 }
62
63 ActorSleepTransition::ActorSleepTransition(aid_t issuer, int times_considered, std::stringstream& stream)
64     : Transition(Type::ACTOR_SLEEP, issuer, times_considered)
65 {
66   XBT_DEBUG("ActorSleepTransition()");
67 }
68 std::string ActorSleepTransition::to_string(bool verbose) const
69 {
70   return xbt::string_printf("ActorSleep()");
71 }
72 bool ActorSleepTransition::depends(const Transition* other) const
73 {
74   // Actions executed by the same actor are always dependent
75   if (other->aid_ == aid_)
76     return true;
77
78   // Sleeping is indep with any other transitions: always enabled, not impacted by any transition
79   return false;
80 }
81
82 bool ActorSleepTransition::reversible_race(const Transition* other) const
83 {
84   switch (type_) {
85     case Type::ACTOR_SLEEP:
86       return true; // Always enabled
87     default:
88       xbt_die("Unexpected transition type %s", to_c_str(type_));
89   }
90 }
91
92 } // namespace simgrid::mc