Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
improve an error message
[simgrid.git] / src / simix / smx_synchro.cpp
index 090c872..afb5783 100644 (file)
@@ -4,9 +4,11 @@
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
+#include "src/surf/surf_interface.hpp"
 #include "smx_private.h"
 #include "xbt/log.h"
 
+#include "src/simix/SynchroRaw.hpp"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_synchro, simix,
                                 "SIMIX Synchronization (mutex, semaphores and conditions)");
@@ -24,13 +26,10 @@ static smx_synchro_t SIMIX_synchro_wait(sg_host_t smx_host, double timeout)
 {
   XBT_IN("(%p, %f)",smx_host,timeout);
 
-  smx_synchro_t sync;
-  sync = (smx_synchro_t) xbt_mallocator_get(simix_global->synchro_mallocator);
-  sync->type = SIMIX_SYNC_SYNCHRO;
-  sync->name = xbt_strdup("synchro");
-  sync->synchro.sleep = surf_host_sleep(smx_host, timeout);
-
-  surf_action_set_data(sync->synchro.sleep, sync);
+  simgrid::simix::Raw *sync = new simgrid::simix::Raw();
+  sync->name = nullptr;
+  sync->sleep = surf_host_sleep(smx_host, timeout);
+  sync->sleep->setData(sync);
   XBT_OUT();
   return sync;
 }
@@ -68,25 +67,23 @@ void SIMIX_synchro_stop_waiting(smx_process_t process, smx_simcall_t simcall)
 
 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();
+  simgrid::simix::Raw *raw = static_cast<simgrid::simix::Raw*>(synchro);
+
+  raw->sleep->unref();
+  delete raw;
 }
 
 void SIMIX_post_synchro(smx_synchro_t synchro)
 {
   XBT_IN("(%p)",synchro);
-  xbt_assert(synchro->type == SIMIX_SYNC_SYNCHRO);
-  if (surf_action_get_state(synchro->synchro.sleep) == SURF_ACTION_FAILED)
-    synchro->state = SIMIX_FAILED;
-  else if(surf_action_get_state(synchro->synchro.sleep) == SURF_ACTION_DONE)
-    synchro->state = SIMIX_SRC_TIMEOUT;
+  simgrid::simix::Raw *raw = static_cast<simgrid::simix::Raw*>(synchro);
+  if (raw->sleep->getState() == simgrid::surf::Action::State::failed)
+    raw->state = SIMIX_FAILED;
+  else if(raw->sleep->getState() == simgrid::surf::Action::State::done)
+    raw->state = SIMIX_SRC_TIMEOUT;
 
-  SIMIX_synchro_finish(synchro);  
+  SIMIX_synchro_finish(raw);
   XBT_OUT();
 }
 
@@ -211,8 +208,8 @@ void SIMIX_mutex_unlock(smx_mutex_t mutex, smx_process_t issuer)
 
   /* If the mutex is not owned by the issuer, that's not good */
   if (issuer != mutex->owner)
-         THROWF(mismatch_error, 0, "Cannot release that mutex: it was locked by %s (pid:%d), not by you.",
-                         SIMIX_process_get_name(mutex->owner),SIMIX_process_get_PID(mutex->owner));
+    THROWF(mismatch_error, 0, "Cannot release that mutex: it was locked by %s (pid:%d), not by you.",
+        SIMIX_process_get_name(mutex->owner),SIMIX_process_get_PID(mutex->owner));
 
   if (xbt_swag_size(mutex->sleeping) > 0) {
     /*process to wake up */
@@ -283,7 +280,7 @@ void simcall_HANDLER_cond_wait(smx_simcall_t simcall, smx_cond_t cond, smx_mutex
  * \param simcall the simcall
  */
 void simcall_HANDLER_cond_wait_timeout(smx_simcall_t simcall, smx_cond_t cond,
-                                smx_mutex_t mutex, double timeout)
+                     smx_mutex_t mutex, double timeout)
 {
   XBT_IN("(%p)",simcall);
   smx_process_t issuer = simcall->issuer;