+static void _SIMIX_cond_wait(smx_cond_t cond, smx_mutex_t mutex, double timeout,
+ smx_process_t issuer, smx_simcall_t simcall)
+{
+ XBT_IN("(%p, %p, %f, %p,%p)",cond,mutex,timeout,issuer,simcall);
+ smx_action_t sync_act = NULL;
+
+ XBT_DEBUG("Wait condition %p", cond);
+
+ /* If there is a mutex unlock it */
+ /* FIXME: what happens if the issuer is not the owner of the mutex? */
+ if (mutex != NULL) {
+ cond->mutex = mutex;
+ SIMIX_mutex_unlock(mutex, issuer);
+ }
+
+ sync_act = SIMIX_synchro_wait(issuer->smx_host, timeout);
+ xbt_fifo_unshift(sync_act->simcalls, simcall);
+ issuer->waiting_action = sync_act;
+ xbt_swag_insert(simcall->issuer, cond->sleeping);
+ XBT_OUT();
+}
+
+/**
+ * \brief Signalizes a condition.
+ *
+ * Signalizes a condition and wakes up a sleeping process.
+ * If there are no process sleeping, no action is done.
+ * \param cond A condition
+ */
+void SIMIX_cond_signal(smx_cond_t cond)
+{
+ XBT_IN("(%p)",cond);
+ smx_process_t proc = NULL;
+ smx_mutex_t mutex = NULL;
+ smx_simcall_t simcall = NULL;
+
+ XBT_DEBUG("Signal condition %p", cond);
+
+ /* If there are processes waiting for the condition choose one and try
+ to make it acquire the mutex */
+ if ((proc = xbt_swag_extract(cond->sleeping))) {
+
+ /* Destroy waiter's synchro action */
+ SIMIX_synchro_destroy(proc->waiting_action);
+ proc->waiting_action = NULL;
+
+ /* Now transform the cond wait simcall into a mutex lock one */
+ simcall = &proc->simcall;
+ if(simcall->call == SIMCALL_COND_WAIT)
+ mutex = simcall->cond_wait.mutex;
+ else
+ mutex = simcall->cond_wait_timeout.mutex;
+
+ simcall->call = SIMCALL_MUTEX_LOCK;
+ simcall->mutex_lock.mutex = mutex;
+
+ SIMIX_pre_mutex_lock(simcall);
+ }
+ XBT_OUT();