-
- if ( cond == NULL )
- return SIMIX_WARNING;
- else {
- xbt_assert0( (xbt_swag_size(cond->sleeping) > 0) &&
- (xbt_fifo_size(cond->actions) > 0), "Cannot destroy conditional");
-
- xbt_swag_free(cond->sleeping);
- xbt_fifo_free(cond->actions);
- xbt_free(cond);
- return SIMIX_OK;
- }
+ xbt_assert0((mutex != NULL), "Invalid parameters");
+ smx_action_t act_sleep;
+
+ DEBUG1("Timed wait condition %p", cond);
+ cond->mutex = mutex;
+
+ SIMIX_mutex_unlock(mutex);
+ if (max_duration >= 0) {
+ act_sleep = SIMIX_action_sleep(SIMIX_host_self(), max_duration);
+ SIMIX_register_action_to_condition(act_sleep, cond);
+ __SIMIX_cond_wait(cond);
+ SIMIX_unregister_action_to_condition(act_sleep, cond);
+ if (SIMIX_action_get_state(act_sleep) == SURF_ACTION_DONE) {
+ SIMIX_action_destroy(act_sleep);
+ THROW0(timeout_error, 0, "Condition timeout");
+ } else {
+ SIMIX_action_destroy(act_sleep);
+ }
+
+ } else
+ __SIMIX_cond_wait(cond);
+
+ /* get the mutex again */
+ SIMIX_mutex_lock(cond->mutex);
+
+ return;