-void s4u::ConditionVariable::wait(s4u::Mutex *mutex) {
- simcall_cond_wait(cond_, mutex->mutex_);
+void ConditionVariable::wait(MutexPtr lock)
+{
+ simcall_cond_wait(cond_, lock->mutex_);
+}
+
+void ConditionVariable::wait(std::unique_lock<Mutex>& lock) {
+ simcall_cond_wait(cond_, lock.mutex()->mutex_);
+}
+
+std::cv_status s4u::ConditionVariable::wait_for(std::unique_lock<Mutex>& lock, double timeout) {
+ // The simcall uses -1 for "any timeout" but we don't want this:
+ if (timeout < 0)
+ timeout = 0.0;
+
+ try {
+ simcall_cond_wait_timeout(cond_, lock.mutex()->mutex_, timeout);
+ return std::cv_status::no_timeout;
+ }
+ catch (xbt_ex& e) {
+
+ // If the exception was a timeout, we have to take the lock again:
+ if (e.category == timeout_error) {
+ try {
+ lock.mutex()->lock();
+ return std::cv_status::timeout;
+ }
+ catch (...) {
+ std::terminate();
+ }
+ }
+
+ // Another exception: should we reaquire the lock?
+ std::terminate();
+ }
+ catch (...) {
+ std::terminate();
+ }