Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of https://framagit.org/simgrid/simgrid
[simgrid.git] / src / mc / api / ActorState.hpp
1 /* Copyright (c) 2007-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_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   /** The ID of that actor */
35   const aid_t aid_;
36
37   /** Number of times that the actor was considered to be executed in previous explorations of the state space */
38   unsigned int times_considered_ = 0;
39   /** Maximal amount of times that the actor can be considered for execution in this state.
40    * If times_considered==max_consider, we fully explored that part of the state space */
41   unsigned int max_consider_ = 0;
42
43   /** Whether that actor is initially enabled in this state */
44   bool enabled_;
45
46 public:
47   ActorState(aid_t aid, bool enabled, unsigned int max_consider)
48       : aid_(aid), max_consider_(max_consider), enabled_(enabled)
49   {
50   }
51
52   unsigned int do_consider()
53   {
54     if (max_consider_ <= times_considered_ + 1)
55       mark_done();
56     return times_considered_++;
57   }
58   unsigned int get_times_considered() const { return times_considered_; }
59   aid_t get_aid() const { return aid_; }
60
61   /* returns whether the actor is marked as enabled in the application side */
62   bool is_enabled() const { return enabled_; }
63   /* returns whether the actor is marked as disabled by the exploration algorithm */
64   bool is_disabled() const { return this->state_ == InterleavingType::disabled; }
65   bool is_done() const { return this->state_ == InterleavingType::done; }
66   bool is_todo() const { return this->state_ == InterleavingType::todo; }
67   /** Mark that we should try executing this process at some point in the future of the checker algorithm */
68   void mark_todo()
69   {
70     this->state_            = InterleavingType::todo;
71     this->times_considered_ = 0;
72   }
73   void mark_done() { this->state_ = InterleavingType::done; }
74 };
75
76 } // namespace simgrid::mc
77
78 #endif