Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
MC: rename a file to sort out the mess
[simgrid.git] / src / mc / api / ActorState.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
20   /* Possible exploration status of an actor transition in a state.
21    * Either the checker did not consider the transition, or it was considered and still to do, or considered and done.
22    */
23   enum class InterleavingType {
24     /** This actor transition is not considered by the checker (yet?) */
25     disabled = 0,
26     /** The checker algorithm decided that this actor transitions should be done at some point */
27     todo,
28     /** The checker algorithm decided that this should be done, but it was done in the meanwhile */
29     done,
30   };
31
32   /** Exploration control information */
33   InterleavingType state_ = InterleavingType::disabled;
34
35   /** The ID of that actor */
36   const aid_t aid_;
37
38   /** Number of times that the actor was considered to be executed in previous explorations of the state space */
39   unsigned int times_considered_ = 0;
40   /** Maximal amount of times that the actor can be considered for execution in this state.
41    * If times_considered==max_consider, we fully explored that part of the state space */
42   unsigned int max_consider_ = 0;
43
44   /** Whether that actor is initially enabled in this state */
45   bool enabled_;
46
47 public:
48   ActorState(aid_t aid, bool enabled, unsigned int max_consider)
49       : aid_(aid), max_consider_(max_consider), enabled_(enabled)
50   {
51   }
52
53   unsigned int do_consider()
54   {
55     if (max_consider_ <= times_considered_ + 1)
56       set_done();
57     return times_considered_++;
58   }
59   unsigned int get_times_considered() const { return times_considered_; }
60   aid_t get_aid() const { return aid_; }
61
62   /* returns whether the actor is marked as enabled in the application side */
63   bool is_enabled() const { return enabled_; }
64   /* returns whether the actor is marked as disabled by the exploration algorithm */
65   bool is_disabled() const { return this->state_ == InterleavingType::disabled; }
66   bool is_done() const { return this->state_ == InterleavingType::done; }
67   bool is_todo() const { return this->state_ == InterleavingType::todo; }
68   /** Mark that we should try executing this process at some point in the future of the checker algorithm */
69   void mark_todo()
70   {
71     this->state_            = InterleavingType::todo;
72     this->times_considered_ = 0;
73   }
74   void set_done() { this->state_ = InterleavingType::done; }
75 };
76
77 } // namespace simgrid::mc
78
79 #endif