Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Concatenate nested namespaces (sonar).
[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::kernel::actor {
17
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_;
22
23 public:
24   MutexObserver(ActorImpl* actor, mc::Transition::Type type, activity::MutexImpl* mutex);
25
26   void serialize(std::stringstream& stream) const override;
27   bool is_enabled() override;
28
29   activity::MutexImpl* get_mutex() const { return mutex_; }
30 };
31
32 /* This observer is used for SEM_LOCK and SEM_UNLOCK (only) */
33 class SemaphoreObserver final : public SimcallObserver {
34   mc::Transition::Type type_;
35   activity::SemaphoreImpl* const sem_;
36
37 public:
38   SemaphoreObserver(ActorImpl* actor, mc::Transition::Type type, activity::SemaphoreImpl* sem);
39
40   void serialize(std::stringstream& stream) const override;
41
42   activity::SemaphoreImpl* get_sem() const { return sem_; }
43 };
44
45 /* This observer is ued for SEM_WAIT, that is returning and needs the acquisition (in MC mode) */
46 class SemaphoreAcquisitionObserver final : public ResultingSimcall<bool> {
47   mc::Transition::Type type_;
48   activity::SemAcquisitionImpl* const acquisition_;
49   const double timeout_;
50
51 public:
52   SemaphoreAcquisitionObserver(ActorImpl* actor, mc::Transition::Type type, activity::SemAcquisitionImpl* acqui,
53                                double timeout = -1.0);
54
55   void serialize(std::stringstream& stream) const override;
56   bool is_enabled() override;
57
58   double get_timeout() const { return timeout_; }
59 };
60
61 /* This observer is ued for BARRIER_LOCK and BARRIER_WAIT. WAIT is returning and needs the acquisition */
62 class BarrierObserver final : public ResultingSimcall<bool> {
63   mc::Transition::Type type_;
64   activity::BarrierImpl* const barrier_                = nullptr;
65   activity::BarrierAcquisitionImpl* const acquisition_ = nullptr;
66   const double timeout_;
67
68 public:
69   BarrierObserver(ActorImpl* actor, mc::Transition::Type type, activity::BarrierImpl* bar);
70   BarrierObserver(ActorImpl* actor, mc::Transition::Type type, activity::BarrierAcquisitionImpl* acqui,
71                   double timeout = -1.0);
72
73   void serialize(std::stringstream& stream) const override;
74   bool is_enabled() override;
75
76   double get_timeout() const { return timeout_; }
77 };
78
79 } // namespace simgrid::kernel::actor
80
81 #endif