+static void _SIMIX_cond_wait(smx_cond_t cond, smx_mutex_t mutex, double timeout,
+ smx_process_t issuer, smx_req_t req)
+{
+ smx_action_t sync_act = NULL;
+
+ DEBUG1("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->request_list, req);
+ issuer->waiting_action = sync_act;
+ xbt_swag_insert(req->issuer, cond->sleeping);
+}
+
+/**
+ * \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)
+{
+ smx_process_t proc = NULL;
+ smx_mutex_t mutex = NULL;
+ smx_req_t req = NULL;
+
+ DEBUG1("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 request into a mutex lock one */
+ req = proc->request;
+ if(req->call == REQ_COND_WAIT)
+ mutex = req->cond_wait.mutex;
+ else
+ mutex = req->cond_wait_timeout.mutex;
+
+ req->call = REQ_MUTEX_LOCK;
+ req->mutex_lock.mutex = mutex;
+
+ SIMIX_pre_mutex_lock(req);
+ }
+}
+
+/**
+ * \brief Broadcasts a condition.
+ *
+ * Signal ALL processes waiting on a condition.
+ * If there are no process waiting, no action is done.
+ * \param cond A condition
+ */