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);
42 /** \ingroup m_host_management
44 * \brief Set the user data of a #m_host_t.
46 * This functions checks whether some data has already been associated to \a host
47 or not and attach \a data to \a host if it is possible.
49 MSG_error_t MSG_host_set_data(m_host_t host, void *data)
51 xbt_assert0((host!=NULL), "Invalid parameters");
52 xbt_assert0((host->data == NULL), "Data already set");
60 /** \ingroup m_host_management
62 * \brief Return the user data of a #m_host_t.
64 * This functions checks whether \a host is a valid pointer or not and return
65 the user data associated to \a host if it is possible.
67 void *MSG_host_get_data(m_host_t host)
70 xbt_assert0((host != NULL), "Invalid parameters");
76 /** \ingroup m_host_management
78 * \brief Return the name of the #m_host_t.
80 * This functions checks whether \a host is a valid pointer or not and return
83 const char *MSG_host_get_name(m_host_t host)
86 xbt_assert0((host != NULL) && (host->simdata != NULL), "Invalid parameters");
92 /** \ingroup m_host_management
94 * \brief Return the location on which the current process is executed.
96 m_host_t MSG_host_self(void)
98 return MSG_process_get_host(MSG_process_self());
102 * Real function for destroy a host.
103 * MSG_host_destroy is just a front_end that also removes it from
106 void __MSG_host_destroy(m_host_t host)
108 simdata_host_t simdata = NULL;
111 xbt_assert0((host != NULL), "Invalid parameters");
113 /* Clean Simulator data */
114 simdata = (host)->simdata;
116 for (i = 0; i < msg_global->max_channel; i++)
117 xbt_fifo_free(simdata->mbox[i]);
118 xbt_free(simdata->mbox);
119 xbt_free(simdata->sleeping);
120 xbt_assert0((xbt_fifo_size(simdata->process_list)==0),
121 "Some process are still running on this host");
122 xbt_fifo_free(simdata->process_list);
126 /* Clean host structure */
127 xbt_free(host->name);
133 /** \ingroup m_host_management
134 * \brief Return the current number of #m_host_t.
136 int MSG_get_host_number(void)
138 return (xbt_fifo_size(msg_global->host));
141 /** \ingroup m_host_management
142 * \brief Return a array of all the #m_host_t.
144 m_host_t *MSG_get_host_table(void)
146 return ((m_host_t *)xbt_fifo_to_array(msg_global->host));
149 /** \ingroup m_host_management
150 * \brief Return the number of MSG tasks currently running on a
151 * #m_host_t. The external load is not taken in account.
153 int MSG_get_host_msgload(m_host_t h)
155 xbt_assert0((h!= NULL), "Invalid parameters");
156 xbt_assert0(0, "Not implemented yet");
159 /* return(surf_workstation_resource->extension_public->get_load(h->simdata->host)); */