Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Reorganizing and cleaning the doc
[simgrid.git] / src / msg / task.c
index 552c95a..80a7c72 100644 (file)
@@ -13,6 +13,18 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(task, msg,
 
 static char sprint_buffer[64];
 
+/** \defgroup m_task_management Managing functions of Tasks
+ *  \brief This section describes the task structure of MSG
+ *  (#m_task_t) and the functions for managing it.
+ *
+ *  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
+ *  right level of abstraction for our purposes. A <em>task</em>
+ *  may then be defined by a <em>computing amount</em>, a
+ *  <em>message size</em> and some <em>private data</em>.
+ */
+
 /********************************* Task **************************************/
 /** \ingroup m_task_management
  * \brief Creates a new #m_task_t.
@@ -48,6 +60,10 @@ m_task_t MSG_task_create(const char *name, long double compute_duration,
   simdata->sleeping = xbt_dynar_new(sizeof(m_process_t),NULL);
   simdata->computation_amount = compute_duration;
   simdata->message_size = message_size;
+  simdata->rate = -1.0;
+  simdata->using = 1;
+  simdata->sender = NULL;
+
 
   return task;
 }
@@ -65,6 +81,18 @@ void *MSG_task_get_data(m_task_t task)
   return (task->data);
 }
 
+/** \ingroup m_task_management
+ * \brief Return the sender of a #m_task_t.
+ *
+ * This functions returns the #m_process_t which sent this task
+ */
+m_process_t MSG_task_get_sender(m_task_t task)
+{
+   xbt_assert0(task, "Invalid parameters");
+   return ((simdata_task_t) task->simdata)->sender;
+}
+
+
 /** \ingroup m_task_management
  * \brief Destroy a #m_task_t.
  *
@@ -78,8 +106,12 @@ MSG_error_t MSG_task_destroy(m_task_t task)
   int i;
 
   xbt_assert0((task != NULL), "Invalid parameter");
+
+  task->simdata->using--;
+  if(task->simdata->using>0) return MSG_OK;
+
   xbt_assert0((xbt_dynar_length(task->simdata->sleeping)==0), 
-             "Task still used. Cannot destroy it now!");
+             "Task still used. There is a problem. Cannot destroy it now!");
 
   if(task->name) xbt_free(task->name);
 
@@ -149,13 +181,20 @@ MSG_error_t MSG_task_destroy(m_task_t task)
 
 MSG_error_t __MSG_task_wait_event(m_process_t process, m_task_t task)
 {
+  int _cursor;
+  m_process_t proc = NULL;
+
   xbt_assert0(((task != NULL)
               && (task->simdata != NULL)), "Invalid parameters");
 
-  xbt_dynar_push(task->simdata->sleeping, process);
+  xbt_dynar_push(task->simdata->sleeping, &process);
   process->simdata->waiting_task = task;
-  xbt_context_yield(process->simdata->context);
+  xbt_context_yield();
   process->simdata->waiting_task = NULL;
+  xbt_dynar_foreach(task->simdata->sleeping,_cursor,proc) {
+    if(proc==process) 
+      xbt_dynar_remove_at(task->simdata->sleeping,_cursor,&proc);
+  }
 
   return MSG_OK;
 }