From d90edfc166207c7c7372bfd4f58c6392b8fd4eef Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Fri, 27 Apr 2012 22:47:02 +0200 Subject: [PATCH] Remove the public field msg_host_t->name. Use MSG_host_get_name() --- ChangeLog | 1 + examples/msg/masterslave/masterslave_bypass.c | 4 ++-- .../msg/masterslave/masterslave_cluster.c | 4 ++-- .../msg/masterslave/masterslave_failure.c | 12 +++++----- .../msg/masterslave/masterslave_forwarder.c | 6 ++--- examples/msg/migration/migration.c | 2 +- examples/msg/tracing/ms.c | 8 +++---- examples/msg/tracing/user_variables.c | 2 +- include/msg/datatypes.h | 1 - src/instr/instr_msg_process.c | 4 ++-- src/msg/msg_gos.c | 2 +- src/msg/msg_host.c | 24 ++++--------------- src/msg/msg_process.c | 2 +- 13 files changed, 29 insertions(+), 43 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5583490eaa..11162e1e98 100644 --- a/ChangeLog +++ b/ChangeLog @@ -47,6 +47,7 @@ SimGrid (3.7) NOT RELEASED; urgency=low * Deprecate MSG_get_host_{table,number} Implement MSG_hosts_as_dynar() instead. * Implement MSG_processes_as_dynar() (Closes gforge #13642) + * Remove the public field msg_host_t->name. Use MSG_host_get_name() Simix: * Stabilize the parallel execution mode of user contexts diff --git a/examples/msg/masterslave/masterslave_bypass.c b/examples/msg/masterslave/masterslave_bypass.c index 4c6f2a8cea..343c92fcaa 100644 --- a/examples/msg/masterslave/masterslave_bypass.c +++ b/examples/msg/masterslave/masterslave_bypass.c @@ -199,7 +199,7 @@ int master(int argc, char *argv[]) XBT_INFO("Got %d slave(s) :", slaves_count); for (i = 0; i < slaves_count; i++) - XBT_INFO("\t %s", slaves[i]->name); + XBT_INFO("\t %s", MSG_host_get_name(slaves[i])); XBT_INFO("Got %d task to process :", number_of_tasks); @@ -208,7 +208,7 @@ int master(int argc, char *argv[]) for (i = 0; i < number_of_tasks; i++) { XBT_INFO("Sending \"%s\" to \"%s\"", - todo[i]->name, slaves[i % slaves_count]->name); + todo[i]->name, MSG_host_get_name(slaves[i % slaves_count])); if (MSG_host_self() == slaves[i % slaves_count]) { XBT_INFO("Hey ! It's me ! :)"); } diff --git a/examples/msg/masterslave/masterslave_cluster.c b/examples/msg/masterslave/masterslave_cluster.c index 6f871fdec6..1e54f5e73b 100644 --- a/examples/msg/masterslave/masterslave_cluster.c +++ b/examples/msg/masterslave/masterslave_cluster.c @@ -69,7 +69,7 @@ int master(int argc, char *argv[]) XBT_INFO("Got %d slave(s) :", slaves_count); for (i = 0; i < slaves_count; i++) - XBT_INFO("\t %s", slaves[i]->name); + XBT_INFO("\t %s", MSG_host_get_name(slaves[i])); XBT_INFO("Got %d task to process :", number_of_tasks); @@ -78,7 +78,7 @@ int master(int argc, char *argv[]) for (i = 0; i < number_of_tasks; i++) { XBT_INFO("Sending \"%s\" to \"%s\"", - todo[i]->name, slaves[i % slaves_count]->name); + todo[i]->name, MSG_host_get_name(slaves[i % slaves_count])); if (MSG_host_self() == slaves[i % slaves_count]) { XBT_INFO("Hey ! It's me ! :)"); } diff --git a/examples/msg/masterslave/masterslave_failure.c b/examples/msg/masterslave/masterslave_failure.c index c882244eea..39e7d7e077 100644 --- a/examples/msg/masterslave/masterslave_failure.c +++ b/examples/msg/masterslave/masterslave_failure.c @@ -55,7 +55,7 @@ int master(int argc, char *argv[]) XBT_INFO("Got %d slave(s) :", slaves_count); for (i = 0; i < slaves_count; i++) - XBT_INFO("%s", slaves[i]->name); + XBT_INFO("%s", MSG_host_get_name(slaves[i])); XBT_INFO("Got %d task to process :", number_of_tasks); @@ -79,13 +79,13 @@ int master(int argc, char *argv[]) } else if (a == MSG_TRANSFER_FAILURE) { XBT_INFO ("Mmh. Something went wrong with '%s'. Nevermind. Let's keep going!", - slaves[i % slaves_count]->name); + MSG_host_get_name(slaves[i % slaves_count])); free(task->data); MSG_task_destroy(task); } else if (a == MSG_TIMEOUT) { XBT_INFO ("Mmh. Got timeouted while speaking to '%s'. Nevermind. Let's keep going!", - slaves[i % slaves_count]->name); + MSG_host_get_name(slaves[i % slaves_count])); free(task->data); MSG_task_destroy(task); } else { @@ -109,16 +109,16 @@ int master(int argc, char *argv[]) return 0; } else if (a == MSG_TRANSFER_FAILURE) { XBT_INFO("Mmh. Can't reach '%s'! Nevermind. Let's keep going!", - slaves[i]->name); + MSG_host_get_name(slaves[i])); MSG_task_destroy(task); } else if (a == MSG_TIMEOUT) { XBT_INFO ("Mmh. Got timeouted while speaking to '%s'. Nevermind. Let's keep going!", - slaves[i % slaves_count]->name); + MSG_host_get_name(slaves[i % slaves_count])); MSG_task_destroy(task); } else { XBT_INFO("Hey ?! What's up ? "); - xbt_die("Unexpected behavior with '%s': %d", slaves[i]->name, a); + xbt_die("Unexpected behavior with '%s': %d", MSG_host_get_name(slaves[i]), a); } } diff --git a/examples/msg/masterslave/masterslave_forwarder.c b/examples/msg/masterslave/masterslave_forwarder.c index 1e0d779dcb..4ebb580d8d 100644 --- a/examples/msg/masterslave/masterslave_forwarder.c +++ b/examples/msg/masterslave/masterslave_forwarder.c @@ -77,11 +77,11 @@ int master(int argc, char *argv[]) XBT_INFO("Got %d slaves and %d tasks to process", slaves_count, number_of_tasks); for (i = 0; i < slaves_count; i++) - XBT_DEBUG("%s", slaves[i]->name); + XBT_DEBUG("%s", MSG_host_get_name(slaves[i])); for (i = 0; i < number_of_tasks; i++) { XBT_INFO("Sending \"%s\" to \"%s\"", - todo[i]->name, slaves[i % slaves_count]->name); + todo[i]->name, MSG_host_get_name(slaves[i % slaves_count])); if (MSG_host_self() == slaves[i % slaves_count]) { XBT_INFO("Hey ! It's me ! :)"); } @@ -165,7 +165,7 @@ int forwarder(int argc, char *argv[]) break; } XBT_INFO("Sending \"%s\" to \"%s\"", - MSG_task_get_name(task), slaves[i % slaves_count]->name); + MSG_task_get_name(task), MSG_host_get_name(slaves[i % slaves_count])); MSG_task_send(task, MSG_host_get_name(slaves[i % slaves_count])); i++; } else { diff --git a/examples/msg/migration/migration.c b/examples/msg/migration/migration.c index f0ec59694f..898ac256e8 100644 --- a/examples/msg/migration/migration.c +++ b/examples/msg/migration/migration.c @@ -46,7 +46,7 @@ static int emigrant(int argc, char *argv[]) xbt_mutex_release(mutex); MSG_process_suspend(MSG_process_self()); m_host_t h = MSG_process_get_host(MSG_process_self()); - XBT_INFO("I've been moved on this new host: %s", h->name); + XBT_INFO("I've been moved on this new host: %s", MSG_host_get_name(h)); XBT_INFO("Uh, nothing to do here. Stopping now"); return 0; } /* end_of_emigrant */ diff --git a/examples/msg/tracing/ms.c b/examples/msg/tracing/ms.c index 95b3a28dc3..0b75720cf3 100644 --- a/examples/msg/tracing/ms.c +++ b/examples/msg/tracing/ms.c @@ -41,7 +41,7 @@ int master(int argc, char *argv[]) long slaves_count = atol(argv[4]); //setting the variable "is_master" (previously declared) to value 1 - TRACE_host_variable_set(MSG_host_self()->name, "is_master", 1); + TRACE_host_variable_set(MSG_host_get_name(MSG_host_self()), "is_master", 1); TRACE_mark("msmark", "start_send_tasks"); int i; @@ -50,7 +50,7 @@ int master(int argc, char *argv[]) task = MSG_task_create("task", task_comp_size, task_comm_size, NULL); //setting the variable "task_creation" to value i - TRACE_host_variable_set(MSG_host_self()->name, "task_creation", i); + TRACE_host_variable_set(MSG_host_get_name(MSG_host_self()), "task_creation", i); //setting the category of task to "compute" //the category of a task must be defined before it is sent or executed @@ -73,7 +73,7 @@ int slave(int argc, char *argv[]) { m_task_t task = NULL; - TRACE_host_variable_set(MSG_host_self()->name, "is_slave", 1); + TRACE_host_variable_set(MSG_host_get_name(MSG_host_self()), "is_slave", 1); while (1) { MSG_task_receive(&(task), "master_mailbox"); @@ -83,7 +83,7 @@ int slave(int argc, char *argv[]) } //adding the value returned by MSG_task_get_compute_duration(task) //to the variable "task_computation" - TRACE_host_variable_add(MSG_host_self()->name, + TRACE_host_variable_add(MSG_host_get_name(MSG_host_self()), "task_computation", MSG_task_get_compute_duration(task)); MSG_task_execute(task); diff --git a/examples/msg/tracing/user_variables.c b/examples/msg/tracing/user_variables.c index ea2b959bed..6c63b9d20f 100644 --- a/examples/msg/tracing/user_variables.c +++ b/examples/msg/tracing/user_variables.c @@ -27,7 +27,7 @@ int master(int argc, char *argv[]); int master(int argc, char *argv[]) { - char *hostname = MSG_host_self()->name; + const char *hostname = MSG_host_get_name(MSG_host_self()); int i; //the hostname has an empty HDD with a capacity of 100000 (bytes) diff --git a/include/msg/datatypes.h b/include/msg/datatypes.h index b95dfd9317..79fc90ae62 100644 --- a/include/msg/datatypes.h +++ b/include/msg/datatypes.h @@ -31,7 +31,6 @@ typedef struct s_smx_rvpoint *msg_mailbox_t; /* ******************************** Host ************************************ */ typedef struct m_host { - char *name; /**< @brief host name if any */ smx_host_t smx_host; /**< SIMIX representation of this host */ #ifdef MSG_USE_DEPRECATED msg_mailbox_t *mailboxes; /**< the channels */ diff --git a/src/instr/instr_msg_process.c b/src/instr/instr_msg_process.c index fc96c0cd86..c1a8154f46 100644 --- a/src/instr/instr_msg_process.c +++ b/src/instr/instr_msg_process.c @@ -45,7 +45,7 @@ void TRACE_msg_process_change_host(m_process_t process, m_host_t old_host, m_hos PJ_container_free(existing_container); //create new container on the new_host location - msg = PJ_container_new(instr_process_id(process, str, len), INSTR_MSG_PROCESS, PJ_container_get(new_host->name)); + msg = PJ_container_new(instr_process_id(process, str, len), INSTR_MSG_PROCESS, PJ_container_get(SIMIX_host_get_name(new_host->smx_host))); //end link msg = PJ_container_get(instr_process_id(process, str, len)); @@ -60,7 +60,7 @@ void TRACE_msg_process_create (const char *process_name, int process_pid, m_host int len = INSTR_DEFAULT_STR_SIZE; char str[INSTR_DEFAULT_STR_SIZE]; - container_t host_container = PJ_container_get (host->name); + container_t host_container = PJ_container_get (SIMIX_host_get_name(host->smx_host)); PJ_container_new(instr_process_id_2(process_name, process_pid, str, len), INSTR_MSG_PROCESS, host_container); } } diff --git a/src/msg/msg_gos.c b/src/msg/msg_gos.c index 60dd79109b..5081378556 100644 --- a/src/msg/msg_gos.c +++ b/src/msg/msg_gos.c @@ -175,7 +175,7 @@ MSG_error_t MSG_parallel_task_execute(m_task_t task) xbt_assert(simdata->host_nb, "This is not a parallel task. Go to hell."); - XBT_DEBUG("Parallel computing on %s", p_simdata->m_host->name); + XBT_DEBUG("Parallel computing on %s", SIMIX_host_get_name(p_simdata->m_host->smx_host)); simdata->isused=1; diff --git a/src/msg/msg_host.c b/src/msg/msg_host.c index 40d0ef4471..92f2cf1009 100644 --- a/src/msg/msg_host.c +++ b/src/msg/msg_host.c @@ -25,13 +25,9 @@ /********************************* Host **************************************/ m_host_t __MSG_host_create(smx_host_t workstation) { - const char *name; + const char *name = SIMIX_host_get_name(workstation); m_host_t host = xbt_new0(s_m_host_t, 1); - name = SIMIX_host_get_name(workstation); - /* Host structure */ - host->name = xbt_strdup(name); - host->smx_host = workstation; #ifdef MSG_USE_DEPRECATED @@ -109,11 +105,8 @@ void *MSG_host_get_data(m_host_t host) * This functions checks whether \a host is a valid pointer or not and return its name. */ -const char *MSG_host_get_name(m_host_t host) -{ - - /* Return data */ - return (host->name); +const char *MSG_host_get_name(m_host_t host) { + return SIMIX_host_get_name(host->smx_host); } /** \ingroup m_host_management @@ -127,22 +120,15 @@ m_host_t MSG_host_self(void) /** \ingroup m_host_management * - * \brief Destroys a host + * \brief Destroys a host (internal call only) */ -void __MSG_host_destroy(m_host_t host) -{ - - xbt_assert((host != NULL), "Invalid parameters"); - - /* Clean simulator data */ +void __MSG_host_destroy(m_host_t host) { #ifdef MSG_USE_DEPRECATED if (msg_global->max_channel > 0) free(host->mailboxes); #endif - /* Clean host structure */ - free(host->name); free(host); } diff --git a/src/msg/msg_process.c b/src/msg/msg_process.c index 60e03864b5..dcd5a8c2fb 100644 --- a/src/msg/msg_process.c +++ b/src/msg/msg_process.c @@ -174,7 +174,7 @@ m_process_t MSG_process_create_with_environment(const char *name, /* Let's create the process: SIMIX may decide to start it right now, * even before returning the flow control to us */ - simcall_process_create(&process, name, code, simdata, host->name, + simcall_process_create(&process, name, code, simdata, SIMIX_host_get_name(host->smx_host), argc, argv, properties); if (!process) { -- 2.20.1