Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
MSG: add a function to register a task copy callback
authorChristophe Thiéry <christopho128@gmail.com>
Wed, 11 Jan 2012 12:15:04 +0000 (13:15 +0100)
committerChristophe Thiéry <christopho128@gmail.com>
Wed, 11 Jan 2012 12:43:53 +0000 (13:43 +0100)
include/msg/msg.h
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 bd0472d..f77200a 100644 (file)
@@ -122,6 +122,8 @@ XBT_PUBLIC(m_task_t) MSG_parallel_task_create(const char *name,
                                               void *data);
 XBT_PUBLIC(void *) MSG_task_get_data(m_task_t task);
 XBT_PUBLIC(void) MSG_task_set_data(m_task_t task, void *data);
+XBT_PUBLIC(void) MSG_task_set_copy_callback(void (*callback) (
+    m_task_t task, m_process_t src, m_process_t dst));
 XBT_PUBLIC(m_process_t) MSG_task_get_sender(m_task_t task);
 XBT_PUBLIC(m_host_t) MSG_task_get_source(m_task_t task);
 XBT_PUBLIC(const char *) MSG_task_get_name(m_task_t task);
index 59a644c..404d8bf 100644 (file)
@@ -67,6 +67,7 @@ void MSG_global_init(int *argc, char **argv)
     msg_global->max_channel = 0;
     msg_global->PID = 1;
     msg_global->sent_msg = 0;
+    msg_global->task_copy_callback = NULL;
 
     /* initialization of the action module */
     _MSG_action_init();
@@ -74,6 +75,7 @@ void MSG_global_init(int *argc, char **argv)
     SIMIX_function_register_process_create(MSG_process_create_from_SIMIX);
     SIMIX_function_register_process_cleanup(MSG_process_cleanup_from_SIMIX);
     SIMIX_function_register_process_kill(MSG_process_kill_from_SIMIX);
+    SIMIX_comm_set_copy_data_callback(MSG_comm_copy_data_from_SIMIX);
   }
 #ifdef HAVE_TRACING
   TRACE_start();
index 5346028..9b60866 100644 (file)
@@ -9,7 +9,6 @@
 #include "xbt/log.h"
 #include "xbt/sysdep.h"
 
-
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_gos, msg,
                                 "Logging specific to MSG (gos)");
 
@@ -762,6 +761,23 @@ m_task_t MSG_comm_get_task(msg_comm_t comm)
   return comm->task_received ? *comm->task_received : comm->task_sent;
 }
 
+/**
+ * \brief This function is called by SIMIX to copy the data of a comm.
+ * \param comm the comm
+ * \param buff_size size of the buffer
+ */
+void MSG_comm_copy_data_from_SIMIX(smx_action_t comm, size_t buff_size) {
+
+  // copy the task
+  SIMIX_comm_copy_pointer_callback(comm, buff_size);
+
+  // notify the user callback if any
+  if (msg_global->task_copy_callback) {
+    msg_global->task_copy_callback(SIMIX_req_comm_get_src_data(comm),
+        SIMIX_req_comm_get_src_proc(comm), SIMIX_req_comm_get_dst_proc(comm));
+  }
+}
+
 /** \ingroup msg_gos_functions
  * \brief Put a task on a channel of an host and waits for the end of the
  * transmission.
index b537c04..2daf5ef 100644 (file)
@@ -155,7 +155,7 @@ MSG_mailbox_put_with_timeout(msg_mailbox_t mailbox, m_task_t task,
   TRY {
       smx_action_t comm = SIMIX_req_comm_isend(mailbox, t_simdata->message_size,
                                   t_simdata->rate, task, sizeof(void *),
-                                  NULL, NULL, NULL, 0);
+                                  NULL, NULL, task, 0);
 #ifdef HAVE_TRACING
     if (TRACE_is_enabled()) {
       SIMIX_req_set_category(comm, task->category);
index e8af564..4c5e9e4 100644 (file)
@@ -85,6 +85,7 @@ typedef struct MSG_Global {
   int PID;
   int session;
   unsigned long int sent_msg;   /* Total amount of messages sent during the simulation */
+  void (*task_copy_callback) (m_task_t task, m_process_t src, m_process_t dst);
 } s_MSG_Global_t, *MSG_Global_t;
 
 /*extern MSG_Global_t msg_global;*/
@@ -119,6 +120,7 @@ void MSG_process_create_from_SIMIX(smx_process_t *process, const char *name,
                                    const char *hostname, int argc,
                                    char **argv, xbt_dict_t properties);
 void MSG_process_kill_from_SIMIX(smx_process_t p);
+void MSG_comm_copy_data_from_SIMIX(smx_action_t comm, size_t buff_size);
 
 void _MSG_action_init(void);
 void _MSG_action_exit(void);
index 0aabc18..f453edc 100644 (file)
@@ -104,6 +104,15 @@ void MSG_task_set_data(m_task_t task, void *data)
   task->data = data;
 }
 
+/** \ingroup m_task_management
+ * \brief Sets a function to be called when a task has just been copied.
+ * \param callback a callback function
+ */
+void MSG_task_set_copy_callback(void (*callback)
+    (m_task_t task, m_process_t sender, m_process_t receiver)) {
+  msg_global->task_copy_callback = callback;
+}
+
 /** \ingroup m_task_management
  * \brief Return the sender of a #m_task_t.
  *