Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use the standard model
[simgrid.git] / src / msg / host.c
1 /*      $Id$     */
2
3 /* Copyright (c) 2002,2003,2004 Arnaud Legrand. All rights reserved.        */
4
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. */
7
8 #include"private.h"
9 #include"xbt/sysdep.h"
10 #include "xbt/error.h"
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(host, msg,
12                                 "Logging specific to MSG (host)");
13
14 /********************************* Host **************************************/
15 m_host_t __MSG_host_create(const char *name,
16                          void *workstation,
17                          void *data)
18 {
19   simdata_host_t simdata = xbt_new0(s_simdata_host_t,1);
20   m_host_t host = xbt_new0(s_m_host_t,1);
21   int i;
22
23   /* Host structure */
24   host->name = xbt_strdup(name);
25   host->simdata = simdata;
26   host->data = data;
27
28   simdata->host = workstation;
29
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 */
36
37   xbt_fifo_push(msg_global->host, host);
38
39   return host;
40 }
41
42 /** \ingroup m_host_management
43  *
44  * \brief Set the user data of a #m_host_t.
45  *
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.
48  */
49 MSG_error_t MSG_host_set_data(m_host_t host, void *data)
50 {
51   xbt_assert0((host!=NULL), "Invalid parameters");
52   xbt_assert0((host->data == NULL), "Data already set");
53
54   /* Assign data */
55   host->data = data;
56
57   return MSG_OK;
58 }
59
60 /** \ingroup m_host_management
61  *
62  * \brief Return the user data of a #m_host_t.
63  *
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.
66  */
67 void *MSG_host_get_data(m_host_t host)
68 {
69
70   xbt_assert0((host != NULL), "Invalid parameters");
71
72   /* Return data */
73   return (host->data);
74 }
75
76 /** \ingroup m_host_management
77  *
78  * \brief Return the name of the #m_host_t.
79  *
80  * This functions checks whether \a host is a valid pointer or not and return
81    its name.
82  */
83 const char *MSG_host_get_name(m_host_t host)
84 {
85
86   xbt_assert0((host != NULL) && (host->simdata != NULL), "Invalid parameters");
87
88   /* Return data */
89   return (host->name);
90 }
91
92 /** \ingroup m_host_management
93  *
94  * \brief Return the location on which the current process is executed.
95  */
96 m_host_t MSG_host_self(void)
97 {
98   return MSG_process_get_host(MSG_process_self());
99 }
100
101 /**
102  * Real function for destroy a host.
103  * MSG_host_destroy is just  a front_end that also removes it from 
104  * msg_global->host
105  */
106 void __MSG_host_destroy(m_host_t host)
107 {
108   simdata_host_t simdata = NULL;
109   int i = 0;
110
111   xbt_assert0((host != NULL), "Invalid parameters");
112
113   /* Clean Simulator data */
114   simdata = (host)->simdata;
115
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);
123
124   xbt_free(simdata);
125
126   /* Clean host structure */
127   xbt_free(host->name);
128   xbt_free(host);
129
130   return;
131 }
132
133 /** \ingroup m_host_management
134  * \brief Return the current number of #m_host_t.
135  */
136 int MSG_get_host_number(void)
137 {
138   return (xbt_fifo_size(msg_global->host));
139 }
140
141 /** \ingroup m_host_management
142  * \brief Return a array of all the #m_host_t.
143  */
144 m_host_t *MSG_get_host_table(void)
145 {
146   return ((m_host_t *)xbt_fifo_to_array(msg_global->host));
147 }
148
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.
152  */
153 int MSG_get_host_msgload(m_host_t h)
154 {
155   xbt_assert0((h!= NULL), "Invalid parameters");
156   xbt_assert0(0, "Not implemented yet");
157
158   return(0);
159 /*   return(surf_workstation_resource->extension_public->get_load(h->simdata->host)); */
160 }