+ "SIMIX Synchronization (mutex, semaphores and conditions)");
+
+static smx_synchro_t SIMIX_synchro_wait(smx_host_t smx_host, double timeout);
+static void SIMIX_synchro_finish(smx_synchro_t synchro);
+static void _SIMIX_cond_wait(smx_cond_t cond, smx_mutex_t mutex, double timeout,
+ smx_process_t issuer, smx_simcall_t simcall);
+static void _SIMIX_sem_wait(smx_sem_t sem, double timeout, smx_process_t issuer,
+ smx_simcall_t simcall);
+
+/***************************** Raw synchronization *********************************/
+
+static smx_synchro_t SIMIX_synchro_wait(smx_host_t smx_host, double timeout)
+{
+ XBT_IN("(%p, %f)",smx_host,timeout);
+
+ smx_synchro_t sync;
+ sync = xbt_mallocator_get(simix_global->synchro_mallocator);
+ sync->type = SIMIX_SYNC_SYNCHRO;
+ sync->name = xbt_strdup("synchro");
+ sync->synchro.sleep =
+ surf_workstation_sleep(smx_host, timeout);
+
+ surf_action_set_data(sync->synchro.sleep, sync);
+ XBT_OUT();
+ return sync;
+}
+
+void SIMIX_synchro_stop_waiting(smx_process_t process, smx_simcall_t simcall)
+{
+ XBT_IN("(%p, %p)",process,simcall);
+ switch (simcall->call) {
+
+ case SIMCALL_MUTEX_LOCK:
+ xbt_swag_remove(process, simcall_mutex_lock__get__mutex(simcall)->sleeping);
+ break;
+
+ case SIMCALL_COND_WAIT:
+ xbt_swag_remove(process, simcall_cond_wait__get__cond(simcall)->sleeping);
+ break;
+
+ case SIMCALL_COND_WAIT_TIMEOUT:
+ xbt_swag_remove(process, simcall_cond_wait_timeout__get__cond(simcall)->sleeping);
+ break;
+
+ case SIMCALL_SEM_ACQUIRE:
+ xbt_swag_remove(process, simcall_sem_acquire__get__sem(simcall)->sleeping);
+ break;
+
+ case SIMCALL_SEM_ACQUIRE_TIMEOUT:
+ xbt_swag_remove(process, simcall_sem_acquire_timeout__get__sem(simcall)->sleeping);
+ break;
+
+ default:
+ THROW_IMPOSSIBLE;
+ }
+ XBT_OUT();
+}
+
+void SIMIX_synchro_destroy(smx_synchro_t synchro)
+{
+ XBT_IN("(%p)",synchro);
+ XBT_DEBUG("Destroying synchro %p", synchro);
+ xbt_assert(synchro->type == SIMIX_SYNC_SYNCHRO);
+ surf_action_unref(synchro->synchro.sleep);
+ xbt_free(synchro->name);
+ xbt_mallocator_release(simix_global->synchro_mallocator, synchro);
+ XBT_OUT();
+}