Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Solaris segfaults when asked to print NULL
[simgrid.git] / src / msg / m_process.c
index 2a18ad2..f47ed40 100644 (file)
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(m_process, msg,
                                "Logging specific to MSG (process)");
 
+/** \defgroup m_process_management Management Functions of Agents
+ *  \brief This section describes the agent structure of MSG
+ *  (#m_process_t) and the functions for managing it.
+ *
+ *  We need to simulate many independent scheduling decisions, so
+ *  the concept of <em>process</em> is at the heart of the
+ *  simulator. A process may be defined as a <em>code</em>, with
+ *  some <em>private data</em>, executing in a <em>location</em>.
+ *  \see m_process_t
+ */
+
 /******************************** Process ************************************/
 /** \ingroup m_process_management
  * \brief Creates and runs a new #m_process_t.
@@ -29,18 +40,18 @@ m_process_t MSG_process_create(const char *name,
 static void MSG_process_cleanup(void *arg)
 {
 
-  PAJE_PROCESS_FREE(arg);
-
   while(((m_process_t)arg)->simdata->paje_state) {
     PAJE_PROCESS_POP_STATE((m_process_t)arg);
   }
 
+  PAJE_PROCESS_FREE(arg);
+
   xbt_fifo_remove(msg_global->process_list, arg);
   xbt_fifo_remove(msg_global->process_to_run, arg);
   xbt_fifo_remove(((m_process_t) arg)->simdata->host->simdata->process_list, arg);
-  xbt_free(((m_process_t) arg)->name);
-  xbt_free(((m_process_t) arg)->simdata);
-  xbt_free(arg);
+  free(((m_process_t) arg)->name);
+  free(((m_process_t) arg)->simdata);
+  free(arg);
 }
 
 /** \ingroup m_process_management
@@ -307,7 +318,7 @@ int MSG_process_self_PPID(void)
  */
 m_process_t MSG_process_self(void)
 {
-  return msg_global->current_process;
+  return msg_global ? msg_global->current_process : NULL;
 }
 
 /** \ingroup m_process_management
@@ -471,3 +482,15 @@ int __MSG_process_isBlocked(m_process_t process)
 
   return (process->simdata->blocked);
 }
+
+
+const char* xbt_procname(void) {
+  const char res = NULL;
+  m_process_t process = MSG_process_self();
+  if ((process != NULL) && (process->simdata))
+    res = MSG_process_get_name(process);
+  if (res) 
+    return res;
+  else
+    return "";
+}