A
lgorithmique
N
umérique
D
istribuée
Public GIT Repository
projects
/
simgrid.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Reduce the coupling between main library and ruby bindings
[simgrid.git]
/
src
/
simix
/
smx_host.c
diff --git
a/src/simix/smx_host.c
b/src/simix/smx_host.c
index
e26ffb6
..
fd71067
100644
(file)
--- a/
src/simix/smx_host.c
+++ b/
src/simix/smx_host.c
@@
-1,7
+1,5
@@
-/* $Id$ */
-
-/* Copyright (c) 2007 Arnaud Legrand, Bruno Donassolo.
- All rights reserved. */
+/* Copyright (c) 2007, 2008, 2009, 2010. The SimGrid Team.
+ * All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
@@
-9,35
+7,33
@@
#include "private.h"
#include "xbt/sysdep.h"
#include "xbt/log.h"
#include "private.h"
#include "xbt/sysdep.h"
#include "xbt/log.h"
+#include "xbt/dict.h"
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_host, simix,
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_host, simix,
- "Logging specific to SIMIX (hosts)");
+
"Logging specific to SIMIX (hosts)");
/********************************* Host **************************************/
smx_host_t __SIMIX_host_create(const char *name,
/********************************* Host **************************************/
smx_host_t __SIMIX_host_create(const char *name,
- void *workstation, void *data)
+
void *workstation, void *data)
{
{
- smx_simdata_host_t simdata = xbt_new0(s_smx_simdata_host_t, 1);
- smx_host_t host = xbt_new0(s_smx_host_t, 1);
+ smx_host_t smx_host = xbt_new0(s_smx_host_t, 1);
s_smx_process_t proc;
/* Host structure */
s_smx_process_t proc;
/* Host structure */
- host->name = xbt_strdup(name);
- host->simdata = simdata;
- host->data = data;
-
- simdata->host = workstation;
-
- simdata->process_list =
+ smx_host->name = xbt_strdup(name);
+ smx_host->data = data;
+ smx_host->host = workstation;
+ smx_host->process_list =
xbt_swag_new(xbt_swag_offset(proc, host_proc_hookup));
xbt_swag_new(xbt_swag_offset(proc, host_proc_hookup));
- /* Update global variables */
- xbt_fifo_unshift(simix_global->host, host);
+ /* Update global variables */
+ xbt_dict_set(simix_global->host, smx_host->name, smx_host,
+ &__SIMIX_host_destroy);
- return host;
+ return
smx_
host;
}
}
-/**
+/**
* \brief Set the user data of a #smx_host_t.
*
* This functions checks whether some data has already been associated to \a host or not and attach \a data to \a host if it is possible.
* \brief Set the user data of a #smx_host_t.
*
* This functions checks whether some data has already been associated to \a host or not and attach \a data to \a host if it is possible.
@@
-45,7
+41,7
@@
smx_host_t __SIMIX_host_create(const char *name,
* \param data User data
*
*/
* \param data User data
*
*/
-void SIMIX_host_set_data(smx_host_t host, void *data)
+
XBT_INLINE
void SIMIX_host_set_data(smx_host_t host, void *data)
{
xbt_assert0((host != NULL), "Invalid parameters");
xbt_assert0((host->data == NULL), "Data already set");
{
xbt_assert0((host != NULL), "Invalid parameters");
xbt_assert0((host->data == NULL), "Data already set");
@@
-62,63
+58,59
@@
void SIMIX_host_set_data(smx_host_t host, void *data)
* This functions checks whether \a host is a valid pointer or not and return the user data associated to \a host if it is possible.
* \param host SIMIX host
*/
* This functions checks whether \a host is a valid pointer or not and return the user data associated to \a host if it is possible.
* \param host SIMIX host
*/
-void *SIMIX_host_get_data(smx_host_t host)
+
XBT_INLINE
void *SIMIX_host_get_data(smx_host_t host)
{
xbt_assert0((host != NULL), "Invalid parameters");
/* Return data */
{
xbt_assert0((host != NULL), "Invalid parameters");
/* Return data */
- return
(host->data)
;
+ return
host->data
;
}
}
-/**
+/**
* \brief Return the name of the #smx_host_t.
*
* This functions checks whether \a host is a valid pointer or not and return its name.
* \param host SIMIX host
*/
* \brief Return the name of the #smx_host_t.
*
* This functions checks whether \a host is a valid pointer or not and return its name.
* \param host SIMIX host
*/
-const char *SIMIX_host_get_name(smx_host_t host)
+
XBT_INLINE
const char *SIMIX_host_get_name(smx_host_t host)
{
{
- xbt_assert0((host != NULL)
- && (host->simdata != NULL), "Invalid parameters");
+ xbt_assert0((host != NULL), "Invalid parameters");
/* Return data */
/* Return data */
- return
(host->name)
;
+ return
host->name
;
}
}
-/**
+/**
* \brief Return the location on which the current process is executed.
*
* Return the host, more details in #SIMIX_process_get_host
* \return SIMIX host
*/
* \brief Return the location on which the current process is executed.
*
* Return the host, more details in #SIMIX_process_get_host
* \return SIMIX host
*/
-smx_host_t SIMIX_host_self(void)
+
XBT_INLINE
smx_host_t SIMIX_host_self(void)
{
return SIMIX_process_get_host(SIMIX_process_self());
}
/*
* Real function for destroy a host.
{
return SIMIX_process_get_host(SIMIX_process_self());
}
/*
* Real function for destroy a host.
- * MSG_host_destroy is just a front_end that also removes it from
+ * MSG_host_destroy is just a front_end that also removes it from
* msg_global->host
*/
* msg_global->host
*/
-void __SIMIX_host_destroy(
smx_host_t host
)
+void __SIMIX_host_destroy(
void *h
)
{
{
- smx_
simdata_host_t simdata = NULL
;
+ smx_
host_t host = (smx_host_t) h
;
xbt_assert0((host != NULL), "Invalid parameters");
xbt_assert0((host != NULL), "Invalid parameters");
-
/* Clean Simulator data */
/* Clean Simulator data */
- simdata = host->simdata;
-
- if (xbt_swag_size(simdata->process_list) != 0) {
+ if (xbt_swag_size(host->process_list) != 0) {
char *msg =
char *msg =
- bprintf("Shutting down host %s, but it's not empty:", host->name);
+
bprintf("Shutting down host %s, but it's not empty:", host->name);
char *tmp;
smx_process_t process = NULL;
char *tmp;
smx_process_t process = NULL;
- xbt_swag_foreach(process,
simdata
->process_list) {
+ xbt_swag_foreach(process,
host
->process_list) {
tmp = bprintf("%s\n\t%s", msg, process->name);
free(msg);
msg = tmp;
tmp = bprintf("%s\n\t%s", msg, process->name);
free(msg);
msg = tmp;
@@
-126,9
+118,7
@@
void __SIMIX_host_destroy(smx_host_t host)
THROW1(arg_error, 0, "%s", msg);
}
THROW1(arg_error, 0, "%s", msg);
}
- xbt_swag_free(simdata->process_list);
-
- free(simdata);
+ xbt_swag_free(host->process_list);
/* Clean host structure */
free(host->name);
/* Clean host structure */
free(host->name);
@@
-142,21
+132,40
@@
void __SIMIX_host_destroy(smx_host_t host)
*
* \return Number of hosts
*/
*
* \return Number of hosts
*/
-int SIMIX_host_get_number(void)
+
XBT_INLINE
int SIMIX_host_get_number(void)
{
{
- return (xbt_
fifo
_size(simix_global->host));
+ return (xbt_
dict
_size(simix_global->host));
}
}
+
/**
/**
- * \brief Return a array of all the #smx_host_t.
+ * \brief Return a
n
array of all the #smx_host_t.
*
*
- * \return List of all hosts
+ * \return List of all hosts
(in a newly allocated table)
*/
smx_host_t *SIMIX_host_get_table(void)
{
*/
smx_host_t *SIMIX_host_get_table(void)
{
- return ((smx_host_t *) xbt_fifo_to_array(simix_global->host));
+ smx_host_t *res = xbt_new(smx_host_t, xbt_dict_size(simix_global->host));
+ smx_host_t h;
+ xbt_dict_cursor_t c;
+ char *name;
+ int i = 0;
+
+ xbt_dict_foreach(simix_global->host, c, name, h)
+ res[i++] = h;
+
+ return res;
}
}
+/**
+ * \brief Return a dict of all the #smx_host_t.
+ *
+ * \return List of all hosts (as a #xbt_dict_t)
+ */
+XBT_INLINE xbt_dict_t SIMIX_host_get_dict(void)
+{
+ return simix_global->host;
+}
/**
* \brief Return the speed of the processor.
/**
* \brief Return the speed of the processor.
@@
-165,12
+174,12
@@
smx_host_t *SIMIX_host_get_table(void)
* \param host SIMIX host
* \return Speed
*/
* \param host SIMIX host
* \return Speed
*/
-double SIMIX_host_get_speed(smx_host_t host)
+
XBT_INLINE
double SIMIX_host_get_speed(smx_host_t host)
{
xbt_assert0((host != NULL), "Invalid parameters");
{
xbt_assert0((host != NULL), "Invalid parameters");
- return (surf_workstation_model->
-
extension_public->get_speed(host->simdata
->host, 1.0));
+ return (surf_workstation_model->
extension.workstation.
+
get_speed(host
->host, 1.0));
}
/**
}
/**
@@
-179,12
+188,12
@@
double SIMIX_host_get_speed(smx_host_t host)
* Return the available speed (in Mflop/s).
* \return Speed
*/
* Return the available speed (in Mflop/s).
* \return Speed
*/
-double SIMIX_host_get_available_speed(smx_host_t host)
+
XBT_INLINE
double SIMIX_host_get_available_speed(smx_host_t host)
{
xbt_assert0((host != NULL), "Invalid parameters");
{
xbt_assert0((host != NULL), "Invalid parameters");
- return (surf_workstation_model->
-
extension_public->get_available_speed(host->simdata
->host));
+ return (surf_workstation_model->
extension.workstation.
+
get_available_speed(host
->host));
}
/**
}
/**
@@
-194,20
+203,13
@@
double SIMIX_host_get_available_speed(smx_host_t host)
* \param name The name of an host.
* \return The corresponding host
*/
* \param name The name of an host.
* \return The corresponding host
*/
-smx_host_t SIMIX_host_get_by_name(const char *name)
+
XBT_INLINE
smx_host_t SIMIX_host_get_by_name(const char *name)
{
{
- xbt_fifo_item_t i = NULL;
- smx_host_t host = NULL;
-
xbt_assert0(((simix_global != NULL)
xbt_assert0(((simix_global != NULL)
- && (simix_global->host != NULL)),
- "Environment not set yet");
+
&& (simix_global->host != NULL)),
+
"Environment not set yet");
- xbt_fifo_foreach(simix_global->host, i, host, smx_host_t) {
- if (strcmp(host->name, name) == 0)
- return host;
- }
- return NULL;
+ return xbt_dict_get_or_null(simix_global->host, name);
}
/**
}
/**
@@
-216,13
+218,12
@@
smx_host_t SIMIX_host_get_by_name(const char *name)
* \param host a host
* \return the dynamic array consisting of property names
*/
* \param host a host
* \return the dynamic array consisting of property names
*/
-xbt_dict_t SIMIX_host_get_properties(smx_host_t host)
+
XBT_INLINE
xbt_dict_t SIMIX_host_get_properties(smx_host_t host)
{
{
- xbt_assert0((host != NULL), "Invalid parameters");
-
- return (surf_workstation_model->
- common_public->get_properties(host->simdata->host));
+ xbt_assert0((host != NULL), "Invalid parameters (simix host is NULL)");
+ return surf_workstation_model->extension.
+ workstation.get_properties(host->host);
}
}
@@
-233,11
+234,10
@@
xbt_dict_t SIMIX_host_get_properties(smx_host_t host)
* \param host The SIMIX host
* \return 1 if host is available or 0 if not.
*/
* \param host The SIMIX host
* \return 1 if host is available or 0 if not.
*/
-int SIMIX_host_get_state(smx_host_t host)
+
XBT_INLINE
int SIMIX_host_get_state(smx_host_t host)
{
{
- xbt_assert0((host != NULL), "Invalid parameters");
-
- return (surf_workstation_model->
- extension_public->get_state(host->simdata->host));
+ xbt_assert0((host != NULL), "Invalid parameters (simix host is NULL)");
+ return (surf_workstation_model->extension.workstation.
+ get_state(host->host));
}
}