1 /* Copyright (c) 2019-2023. 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_MUTEX_OBSERVER_HPP
7 #define SIMGRID_MC_MUTEX_OBSERVER_HPP
9 #include "simgrid/forward.h"
10 #include "src/kernel/activity/MutexImpl.hpp"
11 #include "src/kernel/actor/ActorImpl.hpp"
12 #include "src/kernel/actor/SimcallObserver.hpp"
16 namespace simgrid::kernel::actor {
18 /* All the observers of Mutex transitions are very similar, so implement them all together in this class */
19 class MutexObserver final : public SimcallObserver {
20 mc::Transition::Type type_;
21 activity::MutexImpl* const mutex_;
24 MutexObserver(ActorImpl* actor, mc::Transition::Type type, activity::MutexImpl* mutex);
26 void serialize(std::stringstream& stream) const override;
27 std::string to_string() const override;
28 bool is_enabled() override;
30 activity::MutexImpl* get_mutex() const { return mutex_; }
33 /* This observer is used for SEM_LOCK and SEM_UNLOCK (only) */
34 class SemaphoreObserver final : public SimcallObserver {
35 mc::Transition::Type type_;
36 activity::SemaphoreImpl* const sem_;
39 SemaphoreObserver(ActorImpl* actor, mc::Transition::Type type, activity::SemaphoreImpl* sem);
41 void serialize(std::stringstream& stream) const override;
42 std::string to_string() const override;
44 activity::SemaphoreImpl* get_sem() const { return sem_; }
47 /* This observer is ued for SEM_WAIT, that is returning and needs the acquisition (in MC mode) */
48 class SemaphoreAcquisitionObserver final : public ResultingSimcall<bool> {
49 mc::Transition::Type type_;
50 activity::SemAcquisitionImpl* const acquisition_;
51 const double timeout_;
54 SemaphoreAcquisitionObserver(ActorImpl* actor, mc::Transition::Type type, activity::SemAcquisitionImpl* acqui,
55 double timeout = -1.0);
57 void serialize(std::stringstream& stream) const override;
58 std::string to_string() const override;
59 bool is_enabled() override;
61 double get_timeout() const { return timeout_; }
64 /* This observer is used for BARRIER_LOCK and BARRIER_WAIT. WAIT is returning and needs the acquisition */
65 class BarrierObserver final : public ResultingSimcall<bool> {
66 mc::Transition::Type type_;
67 activity::BarrierImpl* const barrier_ = nullptr;
68 activity::BarrierAcquisitionImpl* const acquisition_ = nullptr;
69 const double timeout_;
72 BarrierObserver(ActorImpl* actor, mc::Transition::Type type, activity::BarrierImpl* bar);
73 BarrierObserver(ActorImpl* actor, mc::Transition::Type type, activity::BarrierAcquisitionImpl* acqui,
74 double timeout = -1.0);
76 void serialize(std::stringstream& stream) const override;
77 std::string to_string() const override;
78 bool is_enabled() override;
80 double get_timeout() const { return timeout_; }
83 } // namespace simgrid::kernel::actor