Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
834b9e33a756bc4640509d3cf36c0315e01164d0
[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/actor/ActorImpl.hpp"
11 #include <boost/intrusive/list.hpp>
12
13 namespace simgrid::kernel::activity {
14
15 class XBT_PUBLIC ConditionVariableImpl {
16   MutexImpl* mutex_ = nullptr;
17   s4u::ConditionVariable piface_;
18   actor::SynchroList sleeping_; /* list of sleeping actors*/
19
20   std::atomic_int_fast32_t refcount_{1};
21   friend void intrusive_ptr_add_ref(ConditionVariableImpl* cond);
22   friend void intrusive_ptr_release(ConditionVariableImpl* cond);
23
24 public:
25   ConditionVariableImpl() : piface_(this){};
26
27   void remove_sleeping_actor(actor::ActorImpl& actor) { xbt::intrusive_erase(sleeping_, actor); }
28   const s4u::ConditionVariable* get_iface() const { return &piface_; }
29   s4u::ConditionVariable* get_iface() { return &piface_; }
30   void broadcast();
31   void signal();
32   void wait(MutexImpl* mutex, double timeout, actor::ActorImpl* issuer);
33 };
34 } // namespace simgrid::kernel::activity
35
36 #endif