1 /* Copyright (c) 2019-2021. The SimGrid Team. All rights reserved. */
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. */
6 #ifndef SIMGRID_MC_SIMCALL_INSPECTOR_HPP
7 #define SIMGRID_MC_SIMCALL_INSPECTOR_HPP
9 #include "simgrid/forward.h"
16 class SimcallInspector {
17 kernel::actor::ActorImpl* issuer_;
20 SimcallInspector(kernel::actor::ActorImpl* issuer) : issuer_(issuer) {}
21 kernel::actor::ActorImpl* get_issuer() { return issuer_; }
22 /** Whether this transition can currently be taken without blocking.
24 * For example, a mutex_lock is not enabled when the mutex is not free.
25 * A comm_receive is not enabled before the corresponding send has been issued.
27 virtual bool is_enabled() { return true; }
29 /** Check whether the simcall will still be firable on this execution path
31 * Return true if the simcall can be fired another time, and false if it gave all its content already.
33 * This is not to be mixed with is_enabled(). Even if is_pending() returns true,
34 * is_enabled() may return false at a given point but will eventually return true further
35 * on that execution path.
37 * If is_pending() returns false the first time, it means that the execution path is not branching
38 * on that transition. Only one execution path goes out of that simcall.
40 * is_pending() is to decide whether we should branch a new execution path with this transition while
41 * is_enabled() is about continuing the current execution path with that transition or saving it for later.
43 * This function should also do the choices that the platform would have done in non-MC settings.
44 * For example if it's a waitany, pick the communication that should finish first.
45 * If it's a random(), choose the next value to explore.
47 virtual bool is_pending(int times_considered) { return false; }
49 /** Some simcalls may only be observable under some circumstances.
50 * Most simcalls are not visible from the MC because they don't have an inspector at all. */
51 virtual bool is_visible() { return true; }
52 virtual std::string to_string(int times_considered);
53 virtual std::string dot_label() = 0;
56 class RandomSimcall : public SimcallInspector {
62 RandomSimcall(smx_actor_t actor, int min, int max) : SimcallInspector(actor), min_(min), max_(max) {}
63 bool is_pending(int times_considered) override;
64 std::string to_string(int times_considered) override;
65 std::string dot_label() override;
69 } // namespace simgrid