Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
MC: move the reversible_race logic to the Transition class
[simgrid.git] / src / mc / transition / TransitionAny.hpp
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 #ifndef SIMGRID_MC_TRANSITION_ANY_HPP
7 #define SIMGRID_MC_TRANSITION_ANY_HPP
8
9 #include "src/kernel/actor/SimcallObserver.hpp"
10 #include "src/mc/transition/Transition.hpp"
11 #include "src/mc/transition/TransitionComm.hpp"
12
13 #include <algorithm>
14 #include <sstream>
15 #include <string>
16
17 namespace simgrid::mc {
18
19 class TestAnyTransition : public Transition {
20   std::vector<Transition*> transitions_;
21
22 public:
23   TestAnyTransition(aid_t issuer, int times_considered, std::stringstream& stream);
24   std::string to_string(bool verbose) const override;
25   bool depends(const Transition* other) const override;
26   bool reversible_race(const Transition* other) const override;
27
28   Transition* get_current_transition() const { return transitions_.at(times_considered_); }
29   bool result() const
30   {
31     return std::any_of(begin(transitions_), end(transitions_), [](const Transition* transition) {
32       const auto* tested_transition = static_cast<const CommTestTransition*>(transition);
33       return (tested_transition->get_sender() != -1 && tested_transition->get_receiver() != -1);
34     });
35   }
36 };
37
38 class WaitAnyTransition : public Transition {
39   std::vector<Transition*> transitions_;
40
41 public:
42   WaitAnyTransition(aid_t issuer, int times_considered, std::stringstream& stream);
43   std::string to_string(bool verbose) const override;
44   bool depends(const Transition* other) const override;
45   bool reversible_race(const Transition* other) const override;
46
47   Transition* get_current_transition() const { return transitions_.at(times_considered_); }
48 };
49
50 } // namespace simgrid::mc
51
52 #endif