Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fix: correct trace mask checking
[simgrid.git] / src / msg / m_process.c
index 7664a19..c0f57c5 100644 (file)
@@ -34,12 +34,19 @@ void __MSG_process_cleanup(void *arg)
 {
   /* arg is a pointer to a simix process, we can get the msg process with the field data */
   m_process_t proc = ((smx_process_t) arg)->data;
+#ifdef HAVE_TRACING
+  TRACE_msg_process_end (proc);
+#endif
   xbt_fifo_remove(msg_global->process_list, proc);
   SIMIX_process_cleanup(arg);
-  free(proc->name);
-  proc->name = NULL;
-  free(proc->simdata);
-  proc->simdata = NULL;
+  if (proc->name) {
+    free(proc->name);
+    proc->name = NULL;
+  }
+  if (proc->simdata) {
+    free(proc->simdata);
+    proc->simdata = NULL;
+  }
   free(proc);
 
   return;
@@ -136,19 +143,29 @@ m_process_t MSG_process_create_with_environment(const char *name,
                                                 int argc, char **argv,
                                                 xbt_dict_t properties)
 {
-  simdata_process_t simdata = xbt_new0(s_simdata_process_t, 1);
+  simdata_process_t simdata = NULL;
   m_process_t process = xbt_new0(s_m_process_t, 1);
+  smx_process_t smx_process = NULL;
   xbt_assert0(((code != NULL) && (host != NULL)), "Invalid parameters");
 
+  smx_process = SIMIX_process_create(name, code,
+                                     (void *) process, host->name,
+                                     argc, argv, properties);
+  if (!smx_process) {
+    xbt_free(process);
+    return NULL;
+  }
+
+  simdata = xbt_new0(s_simdata_process_t, 1);
+
   /* Simulator Data */
   simdata->PID = msg_global->PID++;
+  simdata->waiting_action = NULL;
   simdata->waiting_task = NULL;
   simdata->m_host = host;
   simdata->argc = argc;
   simdata->argv = argv;
-  simdata->s_process = SIMIX_process_create(name, code,
-                                            (void *) process, host->name,
-                                            argc, argv, properties);
+  simdata->s_process = smx_process;
 
   if (SIMIX_process_self()) {
     simdata->PPID = MSG_process_get_PID(SIMIX_process_self()->data);
@@ -171,6 +188,9 @@ m_process_t MSG_process_create_with_environment(const char *name,
 
 void _MSG_process_kill_from_SIMIX(void *p)
 {
+#ifdef HAVE_TRACING
+  TRACE_msg_process_kill ((m_process_t) p);
+#endif
   MSG_process_kill((m_process_t) p);
 }
 
@@ -183,18 +203,23 @@ void MSG_process_kill(m_process_t process)
 {
   simdata_process_t p_simdata = process->simdata;
 
+#ifdef HAVE_TRACING
+  TRACE_msg_process_kill (process);
+#endif
+
   DEBUG3("Killing %s(%d) on %s",
          process->name, p_simdata->PID, p_simdata->m_host->name);
 
-  if (p_simdata->waiting_task) {
-    DEBUG1("Canceling waiting task %s", p_simdata->waiting_task->name);
-    if (p_simdata->waiting_task->simdata->compute) {
-      SIMIX_action_cancel(p_simdata->waiting_task->simdata->compute);
-    } else if (p_simdata->waiting_task->simdata->comm) {
-      SIMIX_action_cancel(p_simdata->waiting_task->simdata->comm);
-    }
+  if (p_simdata->waiting_task && p_simdata->waiting_task->simdata->comm) {
+      SIMIX_communication_cancel(p_simdata->waiting_task->simdata->comm);
   }
-
+  if (p_simdata->waiting_action) {
+    DEBUG1("Canceling waiting task %s",
+           SIMIX_action_get_name(p_simdata->waiting_action));
+    SIMIX_action_cancel(p_simdata->waiting_action);
+   }
+  
   xbt_fifo_remove(msg_global->process_list, process);
   SIMIX_process_kill(process->simdata->s_process);
 
@@ -212,6 +237,9 @@ MSG_error_t MSG_process_change_host(m_host_t host)
   m_process_t process = MSG_process_self();
   m_host_t now = process->simdata->m_host;
   process->simdata->m_host = host;
+#ifdef HAVE_TRACING
+  TRACE_msg_process_change_host (process, now, host);
+#endif
   SIMIX_process_change_host(process->simdata->s_process, now->name,
                             host->name);
   return MSG_OK;
@@ -239,7 +267,6 @@ void *MSG_process_get_data(m_process_t process)
 MSG_error_t MSG_process_set_data(m_process_t process, void *data)
 {
   xbt_assert0((process != NULL), "Invalid parameters");
-  xbt_assert0((process->data == NULL), "Data already set");
 
   process->data = data;
 
@@ -403,6 +430,10 @@ MSG_error_t MSG_process_suspend(m_process_t process)
                && (process->simdata)), "Invalid parameters");
   CHECK_HOST();
 
+#ifdef HAVE_TRACING
+  TRACE_msg_process_suspend (process);
+#endif
+
   SIMIX_process_suspend(process->simdata->s_process);
   MSG_RETURN(MSG_OK);
 }
@@ -420,6 +451,10 @@ MSG_error_t MSG_process_resume(m_process_t process)
                && (process->simdata)), "Invalid parameters");
   CHECK_HOST();
 
+#ifdef HAVE_TRACING
+  TRACE_msg_process_resume (process);
+#endif
+
   SIMIX_process_resume(process->simdata->s_process);
   MSG_RETURN(MSG_OK);
 }