Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Do not require doxygen in maintainer mode
[simgrid.git] / src / simix / smx_synchro.c
index 70f2249..42d057b 100644 (file)
@@ -29,7 +29,7 @@ smx_mutex_t SIMIX_mutex_init()
   smx_mutex_t m = xbt_new0(s_smx_mutex_t, 1);
   s_smx_process_t p;           /* useful to initialize sleeping swag */
   /* structures initialization */
-  m->using = 0;
+  m->refcount  = 0;
   m->sleeping = xbt_swag_new(xbt_swag_offset(p, synchro_hookup));
   return m;
 }
@@ -46,7 +46,7 @@ void SIMIX_mutex_lock(smx_mutex_t mutex)
   xbt_assert0((mutex != NULL), "Invalid parameters");
 
 
-  if (mutex->using) {
+  if (mutex->refcount ) {
     /* somebody using the mutex, block */
     xbt_swag_insert(self, mutex->sleeping);
     self->simdata->mutex = mutex;
@@ -59,10 +59,10 @@ void SIMIX_mutex_lock(smx_mutex_t mutex)
       xbt_context_yield();
     }
 
-    mutex->using = 1;
+    mutex->refcount  = 1;
   } else {
     /* mutex free */
-    mutex->using = 1;
+    mutex->refcount  = 1;
   }
   return;
 }
@@ -78,10 +78,10 @@ int SIMIX_mutex_trylock(smx_mutex_t mutex)
 {
   xbt_assert0((mutex != NULL), "Invalid parameters");
 
-  if (mutex->using)
+  if (mutex->refcount )
     return 0;
   else {
-    mutex->using = 1;
+    mutex->refcount  = 1;
     return 1;
   }
 }
@@ -100,11 +100,11 @@ void SIMIX_mutex_unlock(smx_mutex_t mutex)
 
   if (xbt_swag_size(mutex->sleeping) > 0) {
     p = xbt_swag_extract(mutex->sleeping);
-    mutex->using = 0;
+    mutex->refcount  = 0;
     xbt_swag_insert(p, simix_global->process_to_run);
   } else {
     /* nobody to wake up */
-    mutex->using = 0;
+    mutex->refcount  = 0;
   }
   return;
 }
@@ -153,9 +153,10 @@ smx_cond_t SIMIX_cond_init()
  */
 void SIMIX_cond_signal(smx_cond_t cond)
 {
+       smx_process_t proc = NULL;
   DEBUG1("Signal condition %p", cond);
   xbt_assert0((cond != NULL), "Invalid parameters");
-  smx_process_t proc = NULL;
 
   if (xbt_swag_size(cond->sleeping) >= 1) {
     proc = xbt_swag_extract(cond->sleeping);
@@ -232,8 +233,9 @@ void __SIMIX_cond_wait(smx_cond_t cond)
 void SIMIX_cond_wait_timeout(smx_cond_t cond, smx_mutex_t mutex,
                             double max_duration)
 {
-  xbt_assert0((mutex != NULL), "Invalid parameters");
+  
   smx_action_t act_sleep;
+  xbt_assert0((mutex != NULL), "Invalid parameters");
 
   DEBUG1("Timed wait condition %p", cond);
   cond->mutex = mutex;
@@ -268,10 +270,11 @@ void SIMIX_cond_wait_timeout(smx_cond_t cond, smx_mutex_t mutex,
  */
 void SIMIX_cond_broadcast(smx_cond_t cond)
 {
-  xbt_assert0((cond != NULL), "Invalid parameters");
   smx_process_t proc = NULL;
   smx_process_t proc_next = NULL;
 
+   xbt_assert0((cond != NULL), "Invalid parameters");
+
   DEBUG1("Broadcast condition %p", cond);
   xbt_swag_foreach_safe(proc, proc_next, cond->sleeping) {
     xbt_swag_remove(proc, cond->sleeping);
@@ -312,3 +315,17 @@ void SIMIX_cond_destroy(smx_cond_t cond)
     return;
   }
 }
+
+void SIMIX_cond_display_info(smx_cond_t cond)
+{
+  if (cond == NULL)
+    return;
+  else {
+    smx_process_t process = NULL;
+
+    INFO0("Blocked process on this condition:");
+    xbt_swag_foreach(process,cond->sleeping) {
+      INFO2("\t %s running on host %s",process->name,process->simdata->smx_host->name);
+    }
+  }
+}