Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
try to fix ns3 examples. Not sure this was the way intended, but it avoids crashes...
[simgrid.git] / src / kernel / activity / ConditionVariableImpl.hpp
1 /* Copyright (c) 2012-2020. 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_KERNEL_ACTIVITY_CONDITIONVARIABLE_HPP
7 #define SIMGRID_KERNEL_ACTIVITY_CONDITIONVARIABLE_HPP
8
9 #include "simgrid/s4u/ConditionVariable.hpp"
10 #include "src/kernel/actor/ActorImpl.hpp"
11 #include <boost/intrusive/list.hpp>
12
13 namespace simgrid {
14 namespace kernel {
15 namespace activity {
16
17 class XBT_PUBLIC ConditionVariableImpl {
18   MutexImpl* mutex_ = nullptr;
19   s4u::ConditionVariable piface_;
20   actor::SynchroList sleeping_; /* list of sleeping actors*/
21
22   std::atomic_int_fast32_t refcount_{1};
23   friend void intrusive_ptr_add_ref(ConditionVariableImpl* cond);
24   friend void intrusive_ptr_release(ConditionVariableImpl* cond);
25
26 public:
27   ConditionVariableImpl() : piface_(this){};
28   ~ConditionVariableImpl() = default;
29
30   void remove_sleeping_actor(actor::ActorImpl& actor) { xbt::intrusive_erase(sleeping_, actor); }
31   s4u::ConditionVariable* get_iface() { return &piface_; }
32   void broadcast();
33   void signal();
34   void wait(MutexImpl* mutex, double timeout, actor::ActorImpl* issuer);
35 };
36 } // namespace activity
37 } // namespace kernel
38 } // namespace simgrid
39
40 #endif