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 sim_data_host_t sim_data = xbt_new0(s_sim_data_host_t,1);
20 m_host_t host = xbt_new0(s_m_host_t,1);
24 host->name = xbt_strdup(name);
25 host->simdata = sim_data;
28 sim_data->host = workstation;
30 sim_data->mbox = xbt_new0(xbt_fifo_t, msg_global->max_channel);
31 for (i = 0; i < msg_global->max_channel; i++)
32 sim_data->mbox[i] = xbt_fifo_new();
33 sim_data->sleeping = xbt_new0(m_process_t, msg_global->max_channel);
34 /* Update global variables */
36 xbt_fifo_push(msg_global->host, host);
41 /** \ingroup m_host_management
43 * \brief Set the user data of a #m_host_t.
45 * This functions checks whether some data has already been associated to \a host
46 or not and attach \a data to \a host if it is possible.
48 MSG_error_t MSG_host_set_data(m_host_t host, void *data)
50 xbt_assert0((host!=NULL), "Invalid parameters");
51 xbt_assert0((host->data == NULL), "Data already set");
59 /** \ingroup m_host_management
61 * \brief Return the user data of a #m_host_t.
63 * This functions checks whether \a host is a valid pointer or not and return
64 the user data associated to \a host if it is possible.
66 void *MSG_host_get_data(m_host_t host)
69 xbt_assert0((host != NULL), "Invalid parameters");
75 /** \ingroup m_host_management
77 * \brief Return the name of the #m_host_t.
79 * This functions checks whether \a host is a valid pointer or not and return
82 const char *MSG_host_get_name(m_host_t host)
85 xbt_assert0((host != NULL) && (host->simdata != NULL), "Invalid parameters");
91 /** \ingroup m_host_management
93 * \brief Return the location on which the current process is executed.
95 m_host_t MSG_host_self(void)
97 return MSG_process_get_host(MSG_process_self());
101 * Real function for destroy a host.
102 * MSG_host_destroy is just a front_end that also removes it from
105 void __MSG_host_destroy(m_host_t host)
107 sim_data_host_t sim_data = NULL;
110 xbt_assert0((host != NULL), "Invalid parameters");
112 /* Clean Simulator data */
113 sim_data = (host)->simdata;
115 for (i = 0; i < msg_global->max_channel; i++)
116 xbt_fifo_free(sim_data->mbox[i]);
117 xbt_free(sim_data->mbox);
118 xbt_free(sim_data->sleeping);
119 xbt_assert0((xbt_swag_size(&(sim_data->process_list))==0),
120 "Some process are still running on this host");
124 /* Clean host structure */
125 xbt_free(host->name);
131 /** \ingroup m_host_management
132 * \brief Return the current number of #m_host_t.
134 int MSG_get_host_number(void)
136 return (xbt_fifo_size(msg_global->host));
139 /** \ingroup m_host_management
140 * \brief Return a array of all the #m_host_t.
142 m_host_t *MSG_get_host_table(void)
144 return ((m_host_t *)xbt_fifo_to_array(msg_global->host));
147 /** \ingroup m_host_management
148 * \brief Return the number of MSG tasks currently running on a
149 * #m_host_t. The external load is not taken in account.
151 int MSG_get_host_msgload(m_host_t h)
153 xbt_assert0((h!= NULL), "Invalid parameters");
154 xbt_assert0(0, "Not implemented yet");
157 /* return(surf_workstation_resource->extension_public->get_load(h->simdata->host)); */