From: navarrop Date: Thu, 24 Mar 2011 10:35:32 +0000 (+0000) Subject: Remove xbt_dict host from simix. X-Git-Tag: v3.6_beta2~140 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/baca7024fc7c8a8231d947be38fd7627348487fd Remove xbt_dict host from simix. git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@9829 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/include/simix/simix.h b/include/simix/simix.h index 967dd5dbe2..3c810e3c66 100644 --- a/include/simix/simix.h +++ b/include/simix/simix.h @@ -51,7 +51,6 @@ XBT_PUBLIC(void) SIMIX_process_set_function(const char* process_host, double process_kill_time); /*********************************** Host *************************************/ -XBT_PUBLIC(xbt_dict_t) SIMIX_host_get_dict(void); XBT_PUBLIC(smx_host_t) SIMIX_host_get_by_name(const char *name); XBT_PUBLIC(smx_host_t) SIMIX_host_self(void); XBT_PUBLIC(const char*) SIMIX_host_self_get_name(void); diff --git a/src/msg/environment.c b/src/msg/environment.c index 633995ff9e..fca4a9f412 100644 --- a/src/msg/environment.c +++ b/src/msg/environment.c @@ -62,15 +62,16 @@ m_host_t MSG_get_host_by_name(const char *name) */ void MSG_create_environment(const char *file) { - xbt_dict_cursor_t c; - smx_host_t h; + xbt_lib_cursor_t cursor; + void **data; char *name; SIMIX_create_environment(file); /* Initialize MSG hosts */ - xbt_dict_foreach(SIMIX_host_get_dict(), c, name, h) { - __MSG_host_create(h, NULL); + xbt_lib_foreach(host_lib, cursor, name, data) { + if(data[SIMIX_HOST_LEVEL]) + __MSG_host_create((smx_host_t)data[SIMIX_HOST_LEVEL], NULL); } return; } diff --git a/src/msg/global.c b/src/msg/global.c index c7f7d2e94c..7df2150906 100644 --- a/src/msg/global.c +++ b/src/msg/global.c @@ -64,7 +64,6 @@ void MSG_global_init(int *argc, char **argv) msg_global = xbt_new0(s_MSG_Global_t, 1); - msg_global->host = xbt_fifo_new(); msg_global->max_channel = 0; msg_global->PID = 1; msg_global->sent_msg = 0; @@ -179,8 +178,6 @@ int MSG_process_killall(int reset_PIDs) */ MSG_error_t MSG_clean(void) { - xbt_fifo_item_t i = NULL; - m_host_t h = NULL; #ifdef HAVE_TRACING TRACE_surf_release(); @@ -188,11 +185,6 @@ MSG_error_t MSG_clean(void) MSG_process_killall(0); - xbt_fifo_foreach(msg_global->host, i, h, m_host_t) { - __MSG_host_destroy(h); - } - xbt_fifo_free(msg_global->host); - free(msg_global); msg_global = NULL; diff --git a/src/msg/host.c b/src/msg/host.c index 20541bc96a..62ca0d8bfe 100644 --- a/src/msg/host.c +++ b/src/msg/host.c @@ -55,9 +55,7 @@ m_host_t __MSG_host_create(smx_host_t workstation, void *data) } SIMIX_req_host_set_data(workstation, host); - - /* Update global variables */ - xbt_fifo_unshift(msg_global->host, host); + xbt_lib_set(host_lib,name,MSG_HOST_LEVEL,host); return host; } @@ -125,7 +123,6 @@ m_host_t MSG_host_self(void) /* * Real function to destroy a host. * MSG_host_destroy is just a front_end that also removes it from - * msg_global->host */ void __MSG_host_destroy(m_host_t host) { @@ -153,8 +150,6 @@ void __MSG_host_destroy(m_host_t host) /* Clean host structure */ free(host->name); free(host); - - } /** \ingroup m_host_management @@ -162,7 +157,7 @@ void __MSG_host_destroy(m_host_t host) */ int MSG_get_host_number(void) { - return (xbt_fifo_size(msg_global->host)); + return host_lib->count; } /** \ingroup m_host_management @@ -170,7 +165,23 @@ int MSG_get_host_number(void) */ m_host_t *MSG_get_host_table(void) { - return ((m_host_t *) xbt_fifo_to_array(msg_global->host)); + void **array; + int i = 0; + xbt_lib_cursor_t cursor; + char *key; + void **data; + + if (host_lib->count == 0) + return NULL; + else + array = xbt_new0(void *, host_lib->count); + + xbt_lib_foreach(host_lib, cursor, key, data) { + if(get_network_element_type(key) == SURF_NETWORK_ELEMENT_HOST) + array[i++] = data[MSG_HOST_LEVEL]; + } + + return (m_host_t *)array; } /** \ingroup m_host_management diff --git a/src/simix/private.h b/src/simix/private.h index 676d923852..ac5651690d 100644 --- a/src/simix/private.h +++ b/src/simix/private.h @@ -30,7 +30,6 @@ /********************************** Simix Global ******************************/ typedef struct s_smx_global { smx_context_factory_t context_factory; - xbt_dict_t host; xbt_dynar_t process_to_run; xbt_swag_t process_list; xbt_swag_t process_to_destroy; diff --git a/src/simix/smx_global.c b/src/simix/smx_global.c index a486e41fb3..f3da01ed1a 100644 --- a/src/simix/smx_global.c +++ b/src/simix/smx_global.c @@ -72,7 +72,6 @@ void SIMIX_global_init(int *argc, char **argv) simix_global = xbt_new0(s_smx_global_t, 1); - simix_global->host = xbt_dict_new(); simix_global->process_to_run = xbt_dynar_new(sizeof(void *), NULL); simix_global->process_list = xbt_swag_new(xbt_swag_offset(proc, process_hookup)); @@ -142,7 +141,6 @@ void SIMIX_clean(void) simix_global->process_list = NULL; simix_global->process_to_destroy = NULL; xbt_dict_free(&(simix_global->registered_functions)); - xbt_dict_free(&(simix_global->host)); /* Let's free maestro now */ SIMIX_context_free(simix_global->maestro_process->context); diff --git a/src/simix/smx_host.c b/src/simix/smx_host.c index b6eaec1446..b655087917 100644 --- a/src/simix/smx_host.c +++ b/src/simix/smx_host.c @@ -36,8 +36,7 @@ smx_host_t SIMIX_host_create(const char *name, xbt_swag_new(xbt_swag_offset(proc, host_proc_hookup)); /* Update global variables */ - xbt_dict_set(simix_global->host, smx_host->name, smx_host, - &SIMIX_host_destroy); + xbt_lib_set(host_lib,smx_host->name,SIMIX_HOST_LEVEL,smx_host); return smx_host; } @@ -78,23 +77,13 @@ void SIMIX_host_destroy(void *h) return; } -/** - * \brief Returns a dict of all hosts. - * - * \return List of all hosts (as a #xbt_dict_t) - */ -xbt_dict_t SIMIX_host_get_dict(void) -{ - return simix_global->host; -} - smx_host_t SIMIX_host_get_by_name(const char *name) { xbt_assert0(((simix_global != NULL) - && (simix_global->host != NULL)), + && (host_lib != NULL)), "Environment not set yet"); - return xbt_dict_get_or_null(simix_global->host, name); + return xbt_lib_get_or_null(host_lib, name, SIMIX_HOST_LEVEL); } smx_host_t SIMIX_host_self(void)