1 /* Copyright (c) 2006-2016. 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_S4U_COND_VARIABLE_HPP
7 #define SIMGRID_S4U_COND_VARIABLE_HPP
9 #include <condition_variable>
11 #include <utility> // std::swap
13 #include <simgrid/simix.h>
14 #include <simgrid/s4u/mutex.hpp>
21 XBT_PUBLIC_CLASS ConditionVariable {
26 ConditionVariable(ConditionVariable* cond) : cond_(SIMIX_cond_ref(cond->cond_)) {}
29 // Copy+move (with the copy-and-swap idiom):
30 ConditionVariable(ConditionVariable const& cond) : cond_(SIMIX_cond_ref(cond.cond_)) {}
31 friend void swap(ConditionVariable& first, ConditionVariable& second)
34 swap(first.cond_, second.cond_);
36 ConditionVariable& operator=(ConditionVariable cond)
41 ConditionVariable(ConditionVariable&& cond) : cond_(nullptr)
48 return cond_ != nullptr;
54 void wait(std::unique_lock<Mutex>& lock);
55 // TODO, return std::cv_status
56 std::cv_status wait_for(std::unique_lock<Mutex>& lock, double duration);
59 /** Variant which takes a predice */
61 void wait(std::unique_lock<Mutex>& lock, P pred)
67 // TODO, return std::cv_status
80 }} // namespace simgrid::s4u
82 #endif /* SIMGRID_S4U_COND_VARIABLE_HPP */