Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fix the logic of refcount in msg_task_t by ... killing it. It's now a boolean indicat...
authormquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Wed, 15 Dec 2010 15:11:04 +0000 (15:11 +0000)
committermquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Wed, 15 Dec 2010 15:11:04 +0000 (15:11 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@9252 48e7efb5-ca39-0410-a469-dd3cf9ba447f

src/msg/gos.c
src/msg/msg_mailbox.c
src/msg/private.h
src/msg/task.c

index c272f1e..92dfac4 100644 (file)
@@ -49,9 +49,9 @@ MSG_error_t MSG_task_execute(m_task_t task)
   TRACE_msg_task_execute_start(task);
 #endif
 
-  xbt_assert1((!simdata->compute) && (task->simdata->refcount == 1),
+  xbt_assert1((!simdata->compute) && (task->simdata->isused == 0),
               "This task is executed somewhere else. Go fix your code! %d",
-              task->simdata->refcount);
+              task->simdata->isused);
 
   DEBUG1("Computing on %s", MSG_process_self()->simdata->m_host->name);
 
@@ -61,7 +61,7 @@ MSG_error_t MSG_task_execute(m_task_t task)
 #endif
     return MSG_OK;
   }
-  simdata->refcount++;
+  simdata->isused=1;
   simdata->compute =
       SIMIX_req_host_execute(task->name, SIMIX_host_self(),
                            simdata->computation_amount);
@@ -74,7 +74,7 @@ MSG_error_t MSG_task_execute(m_task_t task)
   SIMIX_req_host_execution_wait(simdata->compute);
   self->simdata->waiting_action = NULL;
 
-  simdata->refcount--;
+  simdata->isused=0;
 
   DEBUG2("Execution task '%s' finished in state %d", task->name, SIMIX_req_host_execution_get_state(task->simdata->compute));
   if (SIMIX_req_host_execution_get_state(task->simdata->compute) == SIMIX_DONE) {
@@ -148,7 +148,7 @@ MSG_parallel_task_create(const char *name, int host_nb,
   simdata->compute = NULL;
   simdata->comm = NULL;
   simdata->rate = -1.0;
-  simdata->refcount = 1;
+  simdata->isused = 0;
   simdata->sender = NULL;
   simdata->receiver = NULL;
   simdata->source = NULL;
@@ -173,7 +173,7 @@ MSG_error_t MSG_parallel_task_execute(m_task_t task)
   simdata = task->simdata;
 
   xbt_assert0((!simdata->compute)
-              && (task->simdata->refcount == 1),
+              && (task->simdata->isused == 0),
               "This task is executed somewhere else. Go fix your code!");
 
   xbt_assert0(simdata->host_nb,
@@ -181,7 +181,7 @@ MSG_error_t MSG_parallel_task_execute(m_task_t task)
 
   DEBUG1("Parallel computing on %s", MSG_process_self()->simdata->m_host->name);
 
-  simdata->refcount++;
+  simdata->isused=1;
 
   simdata->compute =
       SIMIX_req_host_parallel_execute(task->name, simdata->host_nb,
@@ -196,7 +196,7 @@ MSG_error_t MSG_parallel_task_execute(m_task_t task)
 
   DEBUG2("Finished waiting for execution of action %p, state = %d", simdata->compute, SIMIX_req_host_execution_get_state(task->simdata->compute));
 
-  simdata->refcount--;
+  simdata->isused=0;
 
   if (SIMIX_req_host_execution_get_state(task->simdata->compute) == SIMIX_DONE) {
     /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */
@@ -404,12 +404,11 @@ msg_comm_t MSG_task_isend(m_task_t task, const char *alias)
   t_simdata->sender = process;
   t_simdata->source = MSG_host_self();
 
-  xbt_assert0(t_simdata->refcount == 1,
+  xbt_assert0(t_simdata->isused == 0,
               "This task is still being used somewhere else. You cannot send it now. Go fix your code!");
 
-  t_simdata->refcount++;
+  t_simdata->isused=1;
   msg_global->sent_msg++;
-  //process->simdata->waiting_task = task;
 
   /* Send it by calling SIMIX network layer */
 
@@ -473,7 +472,7 @@ void MSG_comm_destroy(msg_comm_t comm)
   if (SIMIX_req_comm_get_src_proc(comm) != SIMIX_process_self()) {
     m_task_t task;
     task = (m_task_t) SIMIX_req_comm_get_src_buff(comm);
-    task->simdata->refcount--;
+    task->simdata->isused=0;
   }
   SIMIX_req_comm_destroy(comm);
 }
@@ -496,7 +495,7 @@ MSG_error_t MSG_comm_wait(msg_comm_t comm, double timeout)
     if (SIMIX_req_comm_get_src_proc(comm) != SIMIX_process_self()) {
       m_task_t task;
       task = (m_task_t) SIMIX_req_comm_get_src_buff(comm);
-      task->simdata->refcount--;
+      task->simdata->isused=0;
     }
 
     /* FIXME: these functions are not tracable */
index fad007c..c77de82 100644 (file)
@@ -99,7 +99,7 @@ MSG_mailbox_get_task_ext(msg_mailbox_t mailbox, m_task_t * task,
     SIMIX_req_comm_wait(comm, timeout);
     SIMIX_req_comm_destroy(comm);
     DEBUG2("Got task %s from %p",(*task)->name,mailbox);
-    (*task)->simdata->refcount--;
+    (*task)->simdata->isused=0;
   }
   CATCH(e) {
     switch (e.category) {
@@ -151,10 +151,10 @@ MSG_mailbox_put_with_timeout(msg_mailbox_t mailbox, m_task_t task,
   t_simdata->sender = process;
   t_simdata->source = MSG_host_self();
 
-  xbt_assert0(t_simdata->refcount == 1,
+  xbt_assert0(t_simdata->isused == 0,
               "This task is still being used somewhere else. You cannot send it now. Go fix your code!");
 
-  t_simdata->refcount++;
+  t_simdata->isused=1;
   msg_global->sent_msg++;
 
   process->simdata->waiting_task = task;
@@ -186,8 +186,8 @@ MSG_mailbox_put_with_timeout(msg_mailbox_t mailbox, m_task_t task,
     }
     xbt_ex_free(e);
 
-    /* Decrement the refcount only on failure */
-    t_simdata->refcount--;
+    /* If the send failed, it is not used anymore */
+    t_simdata->isused=0;
   }
 
   process->simdata->waiting_task = NULL;
index 6c6f6e8..17549a9 100644 (file)
@@ -37,7 +37,7 @@ typedef struct simdata_task {
   m_host_t source;
   double priority;
   double rate;
-  int refcount;
+  int isused;  /* Indicates whether the task is used in SIMIX currently */
   int host_nb;                  /* ==0 if sequential task; parallel task if not */
   /*******  Parallel Tasks Only !!!! *******/
   smx_host_t *host_list;
index 88c743d..cc85717 100644 (file)
@@ -68,7 +68,7 @@ m_task_t MSG_task_create(const char *name, double compute_duration,
   simdata->message_size = message_size;
   simdata->rate = -1.0;
   simdata->priority = 1.0;
-  simdata->refcount = 1;
+  simdata->isused = 0;
   simdata->sender = NULL;
   simdata->receiver = NULL;
   simdata->compute = NULL;
@@ -166,8 +166,7 @@ MSG_error_t MSG_task_destroy(m_task_t task)
   xbt_assert0((task != NULL), "Invalid parameter");
 
   /* why? if somebody is using, then you can't free! ok... but will return MSG_OK? when this task will be destroyed? isn't the user code wrong? */
-  task->simdata->refcount--;
-  if (task->simdata->refcount > 0)
+  if (task->simdata->isused > 0)
     return MSG_OK;
 #ifdef HAVE_TRACING
   TRACE_msg_task_destroy(task);