Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' into hypervisor
[simgrid.git] / src / simix / smx_synchro.c
index f5f354d..c0eba11 100644 (file)
@@ -23,14 +23,16 @@ static void _SIMIX_sem_wait(smx_sem_t sem, double timeout, smx_process_t issuer,
 static smx_action_t SIMIX_synchro_wait(smx_host_t smx_host, double timeout)
 {
   XBT_IN("(%p, %f)",smx_host,timeout);
+  surf_model_t ws_model = surf_resource_model(smx_host, SURF_WKS_LEVEL);
+
   smx_action_t action;
   action = xbt_mallocator_get(simix_global->action_mallocator);
   action->type = SIMIX_ACTION_SYNCHRO;
   action->name = xbt_strdup("synchro");
   action->synchro.sleep = 
-    surf_workstation_model->extension.workstation.sleep(smx_host->host, timeout);
+    ws_model->extension.workstation.sleep(smx_host, timeout);
 
-  surf_workstation_model->action_data_set(action->synchro.sleep, action);
+  ws_model->action_data_set(action->synchro.sleep, action);
   XBT_OUT();
   return action;
 }
@@ -41,23 +43,23 @@ void SIMIX_synchro_stop_waiting(smx_process_t process, smx_simcall_t simcall)
   switch (simcall->call) {
 
     case SIMCALL_MUTEX_LOCK:
-      xbt_swag_remove(process, simcall->mutex_lock.mutex->sleeping);
+      xbt_swag_remove(process, simcall_mutex_lock__get__mutex(simcall)->sleeping);
       break;
 
     case SIMCALL_COND_WAIT:
-      xbt_swag_remove(process, simcall->cond_wait.cond->sleeping);
+      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.cond->sleeping);
+      xbt_swag_remove(process, simcall_cond_wait_timeout__get__cond(simcall)->sleeping);
       break;
 
     case SIMCALL_SEM_ACQUIRE:
-      xbt_swag_remove(process, simcall->sem_acquire.sem->sleeping);
+      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.sem->sleeping);
+      xbt_swag_remove(process, simcall_sem_acquire_timeout__get__sem(simcall)->sleeping);
       break;
 
     default:
@@ -70,7 +72,9 @@ void SIMIX_synchro_destroy(smx_action_t action)
 {
   XBT_IN("(%p)",action);
   XBT_DEBUG("Destroying synchro %p", action);
-  action->synchro.sleep->model_type->action_unref(action->synchro.sleep);
+  xbt_assert(action->type == SIMIX_ACTION_SYNCHRO);
+
+  action->synchro.sleep->model_obj->action_unref(action->synchro.sleep);
   xbt_free(action->name);
   xbt_mallocator_release(simix_global->action_mallocator, action);
   XBT_OUT();
@@ -79,9 +83,12 @@ void SIMIX_synchro_destroy(smx_action_t action)
 void SIMIX_post_synchro(smx_action_t action)
 {
   XBT_IN("(%p)",action);
-  if (surf_workstation_model->action_state_get(action->synchro.sleep) == SURF_ACTION_FAILED)
+  xbt_assert(action->type == SIMIX_ACTION_SYNCHRO);
+  surf_model_t ws_model = action->synchro.sleep->model_obj;
+
+  if (ws_model->action_state_get(action->synchro.sleep) == SURF_ACTION_FAILED)
     action->state = SIMIX_FAILED;
-  else if(surf_workstation_model->action_state_get(action->synchro.sleep) == SURF_ACTION_DONE)
+  else if(ws_model->action_state_get(action->synchro.sleep) == SURF_ACTION_DONE)
     action->state = SIMIX_SRC_TIMEOUT;
 
   SIMIX_synchro_finish(action);  
@@ -350,10 +357,9 @@ void SIMIX_cond_signal(smx_cond_t cond)
     /* 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;
+      mutex = simcall_cond_wait__get__mutex(simcall);
     else
-      mutex = simcall->cond_wait_timeout.mutex;
-
+      mutex = simcall_cond_wait_timeout__get__mutex(simcall);
     simcall->call = SIMCALL_MUTEX_LOCK;
 
     SIMIX_pre_mutex_lock(simcall, mutex);
@@ -457,7 +463,6 @@ void SIMIX_sem_release(smx_sem_t sem)
 
   XBT_DEBUG("Sem release semaphore %p", sem);
   if ((proc = xbt_swag_extract(sem->sleeping))) {
-    proc = xbt_swag_extract(sem->sleeping);
     SIMIX_synchro_destroy(proc->waiting_action);
     proc->waiting_action = NULL;
     SIMIX_simcall_answer(&proc->simcall);
@@ -467,9 +472,6 @@ void SIMIX_sem_release(smx_sem_t sem)
   XBT_OUT();
 }
 
-XBT_INLINE int SIMIX_pre_sem_would_block(smx_simcall_t simcall, smx_sem_t sem){
-  return SIMIX_sem_would_block(sem);
-}
 /** @brief Returns true if acquiring this semaphore would block */
 XBT_INLINE int SIMIX_sem_would_block(smx_sem_t sem)
 {