X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/851011012031214525df480e2c5abddb490228fe..c111bd7eb06c7bd66de5a930ebf86f69c7f984df:/include/simgrid/s4u/conditionVariable.hpp diff --git a/include/simgrid/s4u/conditionVariable.hpp b/include/simgrid/s4u/conditionVariable.hpp index ce06ef00ca..2858244ef6 100644 --- a/include/simgrid/s4u/conditionVariable.hpp +++ b/include/simgrid/s4u/conditionVariable.hpp @@ -6,6 +6,7 @@ #ifndef SIMGRID_S4U_COND_VARIABLE_HPP #define SIMGRID_S4U_COND_VARIABLE_HPP +#include #include #include // std::swap @@ -47,33 +48,36 @@ public: return cond_ != nullptr; } - /** - * Wait functions - */ + // Wait functions: + void wait(std::unique_lock& lock); - // TODO, return std::cv_status - void wait_for(std::unique_lock& lock, double duration); - // TODO, wait_until + std::cv_status wait_until(std::unique_lock& lock, double timeout_time); + std::cv_status wait_for(std::unique_lock& lock, double duration); + + // Variants which takes a predicate: - /** Variant which takes a predice */ template void wait(std::unique_lock& lock, P pred) { while (!pred()) wait(lock); } - // TODO, return std::cv_status template - void wait_for(std::unique_lock& lock, double duration, P pred) + bool wait_until(std::unique_lock& lock, double timeout_time, P pred) { while (!pred()) - wait_for(lock, duration); + if (this->wait_until(lock, timeout_time) == std::cv_status::timeout) + return pred(); + return true; + } + template + bool wait_for(std::unique_lock& lock, double duration, P pred) + { + return this->wait_until(lock, SIMIX_get_clock() + duration, std::move(pred)); } - // TODO,wait_until - /** - * Notify functions - */ + // Notify functions + void notify(); void notify_all();