Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[project-description] Fix extraction of the ns-3 version.
[simgrid.git] / src / mc / mc_pattern.hpp
1 /* Copyright (c) 2007-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 #ifndef SIMGRID_MC_PATTERN_H
7 #define SIMGRID_MC_PATTERN_H
8
9 #include "src/kernel/activity/CommImpl.hpp"
10 #include "src/mc/remote/RemotePtr.hpp"
11
12 namespace simgrid::mc {
13
14 /* On every state, each actor has an entry of the following type.
15  * This represents both the actor and its transition because
16  *   an actor cannot have more than one enabled transition at a given time.
17  */
18 class ActorState {
19   /* Possible exploration status of an actor transition in a state.
20    * Either the checker did not consider the transition, or it was considered and still to do, or considered and done.
21    */
22   enum class InterleavingType {
23     /** This actor transition is not considered by the checker (yet?) */
24     disabled = 0,
25     /** The checker algorithm decided that this actor transitions should be done at some point */
26     todo,
27     /** The checker algorithm decided that this should be done, but it was done in the meanwhile */
28     done,
29   };
30
31   /** Exploration control information */
32   InterleavingType state_ = InterleavingType::disabled;
33
34   /** Number of times that the process was considered to be executed */
35   unsigned int times_considered_ = 0;
36
37 public:
38   unsigned int do_consider(unsigned int max_consider)
39   {
40     if (max_consider <= times_considered_ + 1)
41       set_done();
42     return times_considered_++;
43   }
44   unsigned int get_times_considered() const { return times_considered_; }
45
46   bool is_disabled() const { return this->state_ == InterleavingType::disabled; }
47   bool is_done() const { return this->state_ == InterleavingType::done; }
48   bool is_todo() const { return this->state_ == InterleavingType::todo; }
49   /** Mark that we should try executing this process at some point in the future of the checker algorithm */
50   void mark_todo()
51   {
52     this->state_            = InterleavingType::todo;
53     this->times_considered_ = 0;
54   }
55   void set_done() { this->state_ = InterleavingType::done; }
56 };
57
58 } // namespace simgrid::mc
59
60 #endif