Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Rename option multiple use of task and fix leak
authorPaul Bédaride <paul.bedaride@gmail.com>
Tue, 22 Apr 2014 09:26:20 +0000 (11:26 +0200)
committerPaul Bédaride <paul.bedaride@gmail.com>
Tue, 22 Apr 2014 09:26:20 +0000 (11:26 +0200)
src/msg/msg_global.c
src/msg/msg_gos.c
src/msg/msg_mailbox.c
src/msg/msg_private.h
src/msg/msg_task.c

index f00a073..018afcb 100644 (file)
@@ -25,9 +25,9 @@ static void MSG_exit(void);
 
 /********************************* MSG **************************************/
 
-static void _sg_cfg_cb_msg_multiple_backtraces(const char *name, int pos)
+static void _sg_cfg_cb_msg_debug_multiple_use(const char *name, int pos)
 {
-  msg_global->multiple_backtraces = xbt_cfg_get_boolean(_sg_cfg_set, name);
+  msg_global->debug_multiple_use = xbt_cfg_get_boolean(_sg_cfg_set, name);
 }
 
 /**
@@ -46,10 +46,10 @@ void MSG_init_nocheck(int *argc, char **argv) {
 
     msg_global = xbt_new0(s_MSG_Global_t, 1);
 
-    xbt_cfg_register(&_sg_cfg_set, "msg/multiple_backtraces",
-                     "Keep the severals backtraces",
-                     xbt_cfgelm_boolean, 1, 1, _sg_cfg_cb_msg_multiple_backtraces, NULL);
-    xbt_cfg_setdefault_boolean(_sg_cfg_set, "msg/multiple_backtraces", "no");
+    xbt_cfg_register(&_sg_cfg_set, "msg/debug_multiple_use",
+                     "Print backtraces of both processes when there is a conflict of multiple use of a task",
+                     xbt_cfgelm_boolean, 1, 1, _sg_cfg_cb_msg_debug_multiple_use, NULL);
+    xbt_cfg_setdefault_boolean(_sg_cfg_set, "msg/debug_multiple_use", "no");
 
     SIMIX_global_init(argc, argv);
 
index de83be3..7c01ce1 100644 (file)
@@ -71,7 +71,7 @@ msg_error_t MSG_parallel_task_execute(msg_task_t task)
 
 
   TRY {
-    if (msg_global->multiple_backtraces)
+    if (msg_global->debug_multiple_use)
       MSG_BT(simdata->isused, "Using Backtrace");
     else
       simdata->isused = (void*)1;
@@ -105,7 +105,9 @@ msg_error_t MSG_parallel_task_execute(msg_task_t task)
 
     p_simdata->waiting_action = NULL;
 
-    simdata->isused=0;
+    if (msg_global->debug_multiple_use && simdata->isused!=0)
+      xbt_ex_free(*(xbt_ex_t*)simdata->isused);
+    simdata->isused = 0;
 
     XBT_DEBUG("Execution task '%s' finished in state %d",
               task->name, (int)comp_state);
@@ -408,16 +410,18 @@ msg_comm_t MSG_task_isend_internal(msg_task_t task, const char *alias,
   t_simdata->source = ((simdata_process_t) SIMIX_process_self_get_data(process))->m_host;
 
   if (t_simdata->isused != 0) {
-    if (msg_global->multiple_backtraces){
+    if (msg_global->debug_multiple_use){
       XBT_ERROR("This task is already used in there:");
       xbt_backtrace_display(t_simdata->isused);
-      THROWF(unknown_error, 0, "And you try to reuse it from here. You cannot send it now. Go fix your code!");
+      XBT_ERROR("And you try to reuse it from here:");
+      xbt_backtrace_display_current();
     } else {
-      THROWF(unknown_error, 0, "This task is still being used somewhere else. You cannot send it now. Go fix your code! (use --cfg=msg/multiple_backtraces:on to get the backtrace of the other process)");
+      xbt_assert(t_simdata->isused == 0,
+                 "This task is still being used somewhere else. You cannot send it now. Go fix your code! (use --cfg=msg/debug_multiple_use:on to get the backtrace of the other process)");
     }
   }
 
-  if (msg_global->multiple_backtraces)
+  if (msg_global->debug_multiple_use)
     MSG_BT(t_simdata->isused, "Using Backtrace");
   else
     t_simdata->isused = (void*)1;
@@ -626,7 +630,10 @@ int MSG_comm_test(msg_comm_t comm)
 
     if (finished && comm->task_received != NULL) {
       /* I am the receiver */
-      (*comm->task_received)->simdata->isused = 0;
+      simdata_task_t simdata = (*comm->task_received)->simdata;
+      if (msg_global->debug_multiple_use && simdata->isused!=0)
+        xbt_ex_free(*(xbt_ex_t*)simdata->isused);
+      simdata->isused = 0;
     }
   }
   CATCH(e) {
@@ -700,7 +707,10 @@ int MSG_comm_testany(xbt_dynar_t comms)
 
     if (status == MSG_OK && comm->task_received != NULL) {
       /* I am the receiver */
-      (*comm->task_received)->simdata->isused = 0;
+      simdata_task_t simdata = (*comm->task_received)->simdata;
+      if (msg_global->debug_multiple_use && simdata->isused!=0)
+        xbt_ex_free(*(xbt_ex_t*)simdata->isused);
+      simdata->isused = 0;
     }
   }
 
@@ -733,7 +743,10 @@ msg_error_t MSG_comm_wait(msg_comm_t comm, double timeout)
 
     if (comm->task_received != NULL) {
       /* I am the receiver */
-      (*comm->task_received)->simdata->isused = 0;
+      simdata_task_t simdata = (*comm->task_received)->simdata;
+      if (msg_global->debug_multiple_use && simdata->isused!=0)
+        xbt_ex_free(*(xbt_ex_t*)simdata->isused);
+      simdata->isused = 0;
     }
 
     /* FIXME: these functions are not traceable */
@@ -820,7 +833,10 @@ int MSG_comm_waitany(xbt_dynar_t comms)
 
   if (comm->task_received != NULL) {
     /* I am the receiver */
-    (*comm->task_received)->simdata->isused = 0;
+    simdata_task_t simdata = (*comm->task_received)->simdata;
+    if (msg_global->debug_multiple_use && simdata->isused!=0)
+      xbt_ex_free(*(xbt_ex_t*)simdata->isused);
+    simdata->isused = 0;
   }
 
   return finished_index;
index 7e5e577..557b26a 100644 (file)
@@ -132,7 +132,10 @@ MSG_mailbox_get_task_ext_bounded(msg_mailbox_t mailbox, msg_task_t * task,
   TRY {
     simcall_comm_recv(mailbox, task, NULL, NULL, NULL, timeout, rate);
     XBT_DEBUG("Got task %s from %p",(*task)->name,mailbox);
-    (*task)->simdata->isused=0;
+    simdata_task_t simdata = (*task)->simdata;
+    if (msg_global->debug_multiple_use && simdata->isused!=0)
+      xbt_ex_free(*(xbt_ex_t*)simdata->isused);
+    simdata->isused = 0;
   }
   CATCH(e) {
     switch (e.category) {
@@ -181,16 +184,18 @@ MSG_mailbox_put_with_timeout(msg_mailbox_t mailbox, msg_task_t task,
   t_simdata->source = ((simdata_process_t) SIMIX_process_self_get_data(process))->m_host;
 
   if (t_simdata->isused != 0) {
-    if (msg_global->multiple_backtraces){
+    if (msg_global->debug_multiple_use){
       XBT_ERROR("This task is already used in there:");
       xbt_backtrace_display(t_simdata->isused);
-      THROWF(unknown_error, 0, "And you try to reuse it from here. You cannot send it now. Go fix your code!");
+      XBT_ERROR("And you try to reuse it from here:");
+      xbt_backtrace_display_current();
     } else {
-      THROWF(unknown_error, 0, "This task is still being used somewhere else. You cannot send it now. Go fix your code! (use --cfg=msg/multiple_backtraces:on to get the backtrace of the other process)");
+      xbt_assert(t_simdata->isused == 0,
+                 "This task is still being used somewhere else. You cannot send it now. Go fix your code! (use --cfg=msg/debug_multiple_use:on to get the backtrace of the other process)");
     }
   }
 
-  if (msg_global->multiple_backtraces)
+  if (msg_global->debug_multiple_use)
     MSG_BT(t_simdata->isused, "Using Backtrace");
   else
     t_simdata->isused = (void*)1;
@@ -232,6 +237,8 @@ MSG_mailbox_put_with_timeout(msg_mailbox_t mailbox, msg_task_t task,
     xbt_ex_free(e);
 
     /* If the send failed, it is not used anymore */
+    if (msg_global->debug_multiple_use && t_simdata->isused!=0)
+      xbt_ex_free(*(xbt_ex_t*)t_simdata->isused);
     t_simdata->isused = 0;
   }
 
index 480d01e..e5f4cad 100644 (file)
@@ -130,7 +130,7 @@ typedef struct MSG_Global {
   int max_channel;
 #endif
   int session;
-  int multiple_backtraces;
+  int debug_multiple_use;
   unsigned long int sent_msg;   /* Total amount of messages sent during the simulation */
   void (*task_copy_callback) (msg_task_t task, msg_process_t src, msg_process_t dst);
   void_f_pvoid_t process_data_cleanup;
index bdbbc47..7c775a4 100644 (file)
@@ -10,8 +10,8 @@
 #include "xbt/log.h"
 
 /** @addtogroup m_task_management
- *    
- * 
+ *
+ *
  *  Since most scheduling algorithms rely on a concept of task
  *  that can be either <em>computed</em> locally or
  *  <em>transferred</em> on another processor, it seems to be the
@@ -310,7 +310,10 @@ msg_error_t MSG_task_cancel(msg_task_t task)
   }
   else if (task->simdata->comm) {
     simcall_comm_cancel(task->simdata->comm);
-    task->simdata->isused = 0;
+    simdata_task_t simdata = task->simdata;
+    if (msg_global->debug_multiple_use && simdata->isused!=0)
+      xbt_ex_free(*(xbt_ex_t*)simdata->isused);
+    simdata->isused = 0;
   }
   return MSG_OK;
 }
@@ -351,7 +354,7 @@ void MSG_task_set_compute_duration(msg_task_t task,
  * \brief set the amount data attached with a task #msg_task_t.
  *
  * \warning If the transfer is ongoing (already started and not finished),
- * it is not modified by this call. 
+ * it is not modified by this call.
  */
 
 void MSG_task_set_data_size(msg_task_t task,
@@ -428,7 +431,7 @@ double MSG_task_get_data_size(msg_task_t task)
 
 
 /** \ingroup m_task_management
- * \brief Changes the priority of a computation task. This priority doesn't affect 
+ * \brief Changes the priority of a computation task. This priority doesn't affect
  *        the transfer rate. A priority of 2 will make a task receive two times more
  *        cpu power than the other ones.
  *