Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[simgrid.git] / src / kernel / activity / ConditionVariableImpl.hpp
1 /* Copyright (c) 2012-2023. 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/activity/ActivityImpl.hpp"
11 #include "src/kernel/actor/ActorImpl.hpp"
12
13 #include <boost/intrusive/list.hpp>
14
15 namespace simgrid::kernel::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
29   void remove_sleeping_actor(actor::ActorImpl& actor) { xbt::intrusive_erase(sleeping_, actor); }
30   const s4u::ConditionVariable* get_iface() const { return &piface_; }
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 simgrid::kernel::activity
37
38 #endif