Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
ease the reduction of the number of tests, do reduce the number of tests so that...
[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   PAJE_HOST_NEW(host);
40
41   return host;
42 }
43
44 /** \ingroup m_host_management
45  *
46  * \brief Set the user data of a #m_host_t.
47  *
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.
50  */
51 MSG_error_t MSG_host_set_data(m_host_t host, void *data)
52 {
53   xbt_assert0((host!=NULL), "Invalid parameters");
54   xbt_assert0((host->data == NULL), "Data already set");
55
56   /* Assign data */
57   host->data = data;
58
59   return MSG_OK;
60 }
61
62 /** \ingroup m_host_management
63  *
64  * \brief Return the user data of a #m_host_t.
65  *
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.
68  */
69 void *MSG_host_get_data(m_host_t host)
70 {
71
72   xbt_assert0((host != NULL), "Invalid parameters");
73
74   /* Return data */
75   return (host->data);
76 }
77
78 /** \ingroup m_host_management
79  *
80  * \brief Return the name of the #m_host_t.
81  *
82  * This functions checks whether \a host is a valid pointer or not and return
83    its name.
84  */
85 const char *MSG_host_get_name(m_host_t host)
86 {
87
88   xbt_assert0((host != NULL) && (host->simdata != NULL), "Invalid parameters");
89
90   /* Return data */
91   return (host->name);
92 }
93
94 /** \ingroup m_host_management
95  *
96  * \brief Return the location on which the current process is executed.
97  */
98 m_host_t MSG_host_self(void)
99 {
100   return MSG_process_get_host(MSG_process_self());
101 }
102
103 /*
104  * Real function for destroy a host.
105  * MSG_host_destroy is just  a front_end that also removes it from 
106  * msg_global->host
107  */
108 void __MSG_host_destroy(m_host_t host)
109 {
110   simdata_host_t simdata = NULL;
111   int i = 0;
112
113   xbt_assert0((host != NULL), "Invalid parameters");
114
115   PAJE_HOST_FREE(host);
116  
117   /* Clean Simulator data */
118   simdata = (host)->simdata;
119
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);
127
128   xbt_free(simdata);
129
130   /* Clean host structure */
131   xbt_free(host->name);
132   xbt_free(host);
133
134   return;
135 }
136
137 /** \ingroup m_host_management
138  * \brief Return the current number of #m_host_t.
139  */
140 int MSG_get_host_number(void)
141 {
142   return (xbt_fifo_size(msg_global->host));
143 }
144
145 /** \ingroup m_host_management
146  * \brief Return a array of all the #m_host_t.
147  */
148 m_host_t *MSG_get_host_table(void)
149 {
150   return ((m_host_t *)xbt_fifo_to_array(msg_global->host));
151 }
152
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.
156  */
157 int MSG_get_host_msgload(m_host_t h)
158 {
159   xbt_assert0((h!= NULL), "Invalid parameters");
160   xbt_assert0(0, "Not implemented yet");
161
162   return(0);
163 /*   return(surf_workstation_resource->extension_public->get_load(h->simdata->host)); */
164 }