X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/cc14b4de408850d5efb523c8da5b26d0fcfd0a1f..c111bd7eb06c7bd66de5a930ebf86f69c7f984df:/include/simgrid/s4u/conditionVariable.hpp diff --git a/include/simgrid/s4u/conditionVariable.hpp b/include/simgrid/s4u/conditionVariable.hpp index 252a4f153f..2858244ef6 100644 --- a/include/simgrid/s4u/conditionVariable.hpp +++ b/include/simgrid/s4u/conditionVariable.hpp @@ -48,28 +48,36 @@ public: return cond_ != nullptr; } - /** - * Wait functions - */ + // Wait functions: + void wait(std::unique_lock& lock); - // TODO, return std::cv_status + std::cv_status wait_until(std::unique_lock& lock, double timeout_time); std::cv_status wait_for(std::unique_lock& lock, double duration); - // TODO, wait_until - /** Variant which takes a predice */ + // Variants which takes a predicate: + template void wait(std::unique_lock& lock, P pred) { while (!pred()) wait(lock); } + template + bool wait_until(std::unique_lock& lock, double timeout_time, P pred) + { + while (!pred()) + 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, return std::cv_status - // TODO,wait_until + // Notify functions - /** - * Notify functions - */ void notify(); void notify_all();