From 0630e3ce62f6740b2717aa082806a9874bc7593f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Christophe=20Thi=C3=A9ry?= Date: Wed, 11 Jan 2012 13:15:04 +0100 Subject: [PATCH] MSG: add a function to register a task copy callback --- include/msg/msg.h | 2 ++ src/msg/msg_global.c | 2 ++ src/msg/msg_gos.c | 18 +++++++++++++++++- src/msg/msg_mailbox.c | 2 +- src/msg/msg_private.h | 2 ++ src/msg/msg_task.c | 9 +++++++++ 6 files changed, 33 insertions(+), 2 deletions(-) diff --git a/include/msg/msg.h b/include/msg/msg.h index bd0472d045..f77200a050 100644 --- a/include/msg/msg.h +++ b/include/msg/msg.h @@ -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); diff --git a/src/msg/msg_global.c b/src/msg/msg_global.c index 59a644cb47..404d8bf446 100644 --- a/src/msg/msg_global.c +++ b/src/msg/msg_global.c @@ -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(); diff --git a/src/msg/msg_gos.c b/src/msg/msg_gos.c index 5346028394..9b6086607f 100644 --- a/src/msg/msg_gos.c +++ b/src/msg/msg_gos.c @@ -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. diff --git a/src/msg/msg_mailbox.c b/src/msg/msg_mailbox.c index b537c0458c..2daf5ef263 100644 --- a/src/msg/msg_mailbox.c +++ b/src/msg/msg_mailbox.c @@ -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); diff --git a/src/msg/msg_private.h b/src/msg/msg_private.h index e8af564edc..4c5e9e486b 100644 --- a/src/msg/msg_private.h +++ b/src/msg/msg_private.h @@ -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); diff --git a/src/msg/msg_task.c b/src/msg/msg_task.c index 0aabc18413..f453edcbde 100644 --- a/src/msg/msg_task.c +++ b/src/msg/msg_task.c @@ -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. * -- 2.20.1