Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Polymorphic base class destructor should be either public virtual or protected non...
[simgrid.git] / src / kernel / actor / SynchroObserver.hpp
1 /* Copyright (c) 2019-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_MUTEX_OBSERVER_HPP
7 #define SIMGRID_MC_MUTEX_OBSERVER_HPP
8
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"
13
14 #include <string>
15
16 namespace simgrid {
17 namespace kernel {
18 namespace actor {
19
20 /* All the observers of Mutex transitions are very similar, so implement them all together in this class */
21 class MutexObserver final : public SimcallObserver {
22   mc::Transition::Type type_;
23   activity::MutexImpl* const mutex_;
24
25 public:
26   MutexObserver(ActorImpl* actor, mc::Transition::Type type, activity::MutexImpl* mutex);
27
28   void serialize(std::stringstream& stream) const override;
29   bool is_enabled() override;
30
31   activity::MutexImpl* get_mutex() const { return mutex_; }
32 };
33
34 /* This observer is used for SEM_LOCK and SEM_UNLOCK (only) */
35 class SemaphoreObserver final : public SimcallObserver {
36   mc::Transition::Type type_;
37   activity::SemaphoreImpl* const sem_;
38
39 public:
40   SemaphoreObserver(ActorImpl* actor, mc::Transition::Type type, activity::SemaphoreImpl* sem);
41
42   void serialize(std::stringstream& stream) const override;
43
44   activity::SemaphoreImpl* get_sem() const { return sem_; }
45 };
46
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_;
52
53 public:
54   SemaphoreAcquisitionObserver(ActorImpl* actor, mc::Transition::Type type, activity::SemAcquisitionImpl* acqui,
55                                double timeout = -1.0);
56
57   void serialize(std::stringstream& stream) const override;
58   bool is_enabled() override;
59
60   double get_timeout() const { return timeout_; }
61 };
62
63 /* This observer is ued for BARRIER_LOCK and BARRIER_WAIT. WAIT is returning and needs the acquisition */
64 class BarrierObserver final : public ResultingSimcall<bool> {
65   mc::Transition::Type type_;
66   activity::BarrierImpl* const barrier_                = nullptr;
67   activity::BarrierAcquisitionImpl* const acquisition_ = nullptr;
68   const double timeout_;
69
70 public:
71   BarrierObserver(ActorImpl* actor, mc::Transition::Type type, activity::BarrierImpl* bar);
72   BarrierObserver(ActorImpl* actor, mc::Transition::Type type, activity::BarrierAcquisitionImpl* acqui,
73                   double timeout = -1.0);
74
75   void serialize(std::stringstream& stream) const override;
76   bool is_enabled() override;
77
78   double get_timeout() const { return timeout_; }
79 };
80
81 } // namespace actor
82 } // namespace kernel
83 } // namespace simgrid
84
85 #endif