3 /* Copyright (c) 2002,2003,2004 Arnaud Legrand. All rights reserved. */
5 /* This program is free software; you can redistribute it and/or modify it
6 * under the terms of the license (GNU LGPL) which comes with this package. */
10 #include "xbt/error.h"
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(host, msg,
12 "Logging specific to MSG (host)");
14 /********************************* Host **************************************/
15 m_host_t __MSG_host_create(const char *name,
19 simdata_host_t simdata = xbt_new0(s_simdata_host_t,1);
20 m_host_t host = xbt_new0(s_m_host_t,1);
24 host->name = xbt_strdup(name);
25 host->simdata = simdata;
28 simdata->host = workstation;
30 simdata->mbox = xbt_new0(xbt_fifo_t, msg_global->max_channel);
31 for (i = 0; i < msg_global->max_channel; i++)
32 simdata->mbox[i] = xbt_fifo_new();
33 simdata->sleeping = xbt_new0(m_process_t, msg_global->max_channel);
34 simdata->process_list = xbt_fifo_new();
35 /* Update global variables */
37 xbt_fifo_push(msg_global->host, host);
44 /** \ingroup m_host_management
46 * \brief Set the user data of a #m_host_t.
48 * This functions checks whether some data has already been associated to \a host
49 or not and attach \a data to \a host if it is possible.
51 MSG_error_t MSG_host_set_data(m_host_t host, void *data)
53 xbt_assert0((host!=NULL), "Invalid parameters");
54 xbt_assert0((host->data == NULL), "Data already set");
62 /** \ingroup m_host_management
64 * \brief Return the user data of a #m_host_t.
66 * This functions checks whether \a host is a valid pointer or not and return
67 the user data associated to \a host if it is possible.
69 void *MSG_host_get_data(m_host_t host)
72 xbt_assert0((host != NULL), "Invalid parameters");
78 /** \ingroup m_host_management
80 * \brief Return the name of the #m_host_t.
82 * This functions checks whether \a host is a valid pointer or not and return
85 const char *MSG_host_get_name(m_host_t host)
88 xbt_assert0((host != NULL) && (host->simdata != NULL), "Invalid parameters");
94 /** \ingroup m_host_management
96 * \brief Return the location on which the current process is executed.
98 m_host_t MSG_host_self(void)
100 return MSG_process_get_host(MSG_process_self());
104 * Real function for destroy a host.
105 * MSG_host_destroy is just a front_end that also removes it from
108 void __MSG_host_destroy(m_host_t host)
110 simdata_host_t simdata = NULL;
113 xbt_assert0((host != NULL), "Invalid parameters");
115 PAJE_HOST_FREE(host);
117 /* Clean Simulator data */
118 simdata = (host)->simdata;
120 for (i = 0; i < msg_global->max_channel; i++)
121 xbt_fifo_free(simdata->mbox[i]);
122 xbt_free(simdata->mbox);
123 xbt_free(simdata->sleeping);
124 xbt_assert0((xbt_fifo_size(simdata->process_list)==0),
125 "Some process are still running on this host");
126 xbt_fifo_free(simdata->process_list);
130 /* Clean host structure */
131 xbt_free(host->name);
137 /** \ingroup m_host_management
138 * \brief Return the current number of #m_host_t.
140 int MSG_get_host_number(void)
142 return (xbt_fifo_size(msg_global->host));
145 /** \ingroup m_host_management
146 * \brief Return a array of all the #m_host_t.
148 m_host_t *MSG_get_host_table(void)
150 return ((m_host_t *)xbt_fifo_to_array(msg_global->host));
153 /** \ingroup m_host_management
154 * \brief Return the number of MSG tasks currently running on a
155 * #m_host_t. The external load is not taken in account.
157 int MSG_get_host_msgload(m_host_t h)
159 xbt_assert0((h!= NULL), "Invalid parameters");
160 xbt_assert0(0, "Not implemented yet");
163 /* return(surf_workstation_resource->extension_public->get_load(h->simdata->host)); */