1 /* Copyright (c) 2012-2023. The SimGrid Team. All rights reserved. */
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. */
6 #ifndef SIMGRID_KERNEL_ACTIVITY_CONDITIONVARIABLE_HPP
7 #define SIMGRID_KERNEL_ACTIVITY_CONDITIONVARIABLE_HPP
9 #include "simgrid/s4u/ConditionVariable.hpp"
10 #include "src/kernel/actor/ActorImpl.hpp"
11 #include <boost/intrusive/list.hpp>
13 namespace simgrid::kernel::activity {
15 class XBT_PUBLIC ConditionVariableImpl {
16 MutexImpl* mutex_ = nullptr;
17 s4u::ConditionVariable piface_;
18 actor::SynchroList sleeping_; /* list of sleeping actors*/
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);
25 ConditionVariableImpl() : piface_(this){};
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_; }
32 void wait(MutexImpl* mutex, double timeout, actor::ActorImpl* issuer);
34 } // namespace simgrid::kernel::activity