Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Necessity to change the code to implement MSG..
[simgrid.git] / src / msg_simix / m_process.c
1
2 #include "private.h"
3 #include "xbt/sysdep.h"
4 #include "xbt/log.h"
5
6 /** \defgroup m_process_management Management Functions of Agents
7  *  \brief This section describes the agent structure of MSG
8  *  (#m_process_t) and the functions for managing it.
9  *    \htmlonly <!-- DOXYGEN_NAVBAR_LABEL="Agents" --> \endhtmlonly
10  * 
11  *  We need to simulate many independent scheduling decisions, so
12  *  the concept of <em>process</em> is at the heart of the
13  *  simulator. A process may be defined as a <em>code</em>, with
14  *  some <em>private data</em>, executing in a <em>location</em>.
15  *  \see m_process_t
16  */
17
18 /******************************** Process ************************************/
19 /** \ingroup m_process_management
20  * \brief Creates and runs a new #m_process_t.
21  *
22  * Does exactly the same as #MSG_process_create_with_arguments but without 
23    providing standard arguments (\a argc, \a argv, \a start_time, \a kill_time).
24  * \sa MSG_process_create_with_arguments
25  */
26 m_process_t MSG_process_create(const char *name,
27                                m_process_code_t code, void *data,
28                                m_host_t host)
29 {
30   return MSG_process_create_with_arguments(name, code, data, host, -1, NULL);
31 }
32
33 static void MSG_process_cleanup(void *arg)
34 {
35         xbt_die("not implemented yet");
36         return;
37 }
38
39 /** \ingroup m_process_management
40  * \brief Creates and runs a new #m_process_t.
41
42  * A constructor for #m_process_t taking four arguments and returning the 
43  * corresponding object. The structure (and the corresponding thread) is
44  * created, and put in the list of ready process.
45  * \param name a name for the object. It is for user-level information
46    and can be NULL.
47  * \param code is a function describing the behavior of the agent. It
48    should then only use functions described in \ref
49    m_process_management (to create a new #m_process_t for example),
50    in \ref m_host_management (only the read-only functions i.e. whose
51    name contains the word get), in \ref m_task_management (to create
52    or destroy some #m_task_t for example) and in \ref
53    msg_gos_functions (to handle file transfers and task processing).
54  * \param data a pointer to any data one may want to attach to the new
55    object.  It is for user-level information and can be NULL. It can
56    be retrieved with the function \ref MSG_process_get_data.
57  * \param host the location where the new agent is executed.
58  * \param argc first argument passed to \a code
59  * \param argv second argument passed to \a code
60  * \see m_process_t
61  * \return The new corresponding object.
62  */
63 m_process_t MSG_process_create_with_arguments(const char *name,
64                                               m_process_code_t code, void *data,
65                                               m_host_t host, int argc, char **argv)
66 {
67   simdata_process_t simdata = xbt_new0(s_simdata_process_t,1);
68   m_process_t process = xbt_new0(s_m_process_t,1);
69
70   xbt_assert0(((code != NULL) && (host != NULL)), "Invalid parameters");
71
72   /* Simulator Data */
73   simdata->PID = msg_global->PID++;
74   simdata->host = host;
75   simdata->argc = argc;
76   simdata->argv = argv;
77         simdata->smx_process = SIMIX_process_create_with_arguments(name, (smx_process_code_t)code,
78                                                                                                                                                                                                                                                         (void*)process, host->simdata->host, argc, argv );
79
80         if (SIMIX_process_self()) {
81                 simdata->PPID = MSG_process_get_PID(SIMIX_process_self()->data);
82         }
83         else simdata->PPID = -1;
84   simdata->last_errno=MSG_OK;
85
86
87   /* Process structure */
88   process->name = xbt_strdup(name);
89   process->simdata = simdata;
90   process->data = data;
91
92   return process;
93 }
94
95 /** \ingroup m_process_management
96  * \param process poor victim
97  *
98  * This function simply kills a \a process... scarry isn't it ? :)
99  */
100 void MSG_process_kill(m_process_t process)
101 {
102         xbt_die("not implemented yet");
103         return;
104 }
105
106 /** \ingroup m_process_management
107  * \brief Migrates an agent to another location.
108  *
109  * This functions checks whether \a process and \a host are valid pointers
110    and change the value of the #m_host_t on which \a process is running.
111  */
112 MSG_error_t MSG_process_change_host(m_process_t process, m_host_t host)
113 {
114         xbt_die("not implemented yet");
115   return MSG_OK;
116 }
117
118 /** \ingroup m_process_management
119  * \brief Return the user data of a #m_process_t.
120  *
121  * This functions checks whether \a process is a valid pointer or not 
122    and return the user data associated to \a process if it is possible.
123  */
124 void *MSG_process_get_data(m_process_t process)
125 {
126   xbt_assert0((process != NULL), "Invalid parameters");
127
128   return (process->data);
129 }
130
131 /** \ingroup m_process_management
132  * \brief Set the user data of a #m_process_t.
133  *
134  * This functions checks whether \a process is a valid pointer or not 
135    and set the user data associated to \a process if it is possible.
136  */
137 MSG_error_t MSG_process_set_data(m_process_t process,void *data)
138 {
139   xbt_assert0((process != NULL), "Invalid parameters");
140   xbt_assert0((process->data == NULL), "Data already set");
141   
142   process->data = data;
143    
144   return MSG_OK;
145 }
146
147 /** \ingroup m_process_management
148  * \brief Return the location on which an agent is running.
149  *
150  * This functions checks whether \a process is a valid pointer or not 
151    and return the m_host_t corresponding to the location on which \a 
152    process is running.
153  */
154 m_host_t MSG_process_get_host(m_process_t process)
155 {
156   xbt_assert0(((process != NULL) && (process->simdata)), "Invalid parameters");
157
158   return (((simdata_process_t) process->simdata)->host);
159 }
160
161 /** \ingroup m_process_management
162  *
163  * \brief Return a #m_process_t given its PID.
164  *
165  * This functions search in the list of all the created m_process_t for a m_process_t 
166    whose PID is equal to \a PID. If no host is found, \c NULL is returned. 
167    Note that the PID are uniq in the whole simulation, not only on a given host.
168  */
169 m_process_t MSG_process_from_PID(int PID)
170 {
171
172   return NULL;
173 }
174
175 /** \ingroup m_process_management
176  * \brief Returns the process ID of \a process.
177  *
178  * This functions checks whether \a process is a valid pointer or not 
179    and return its PID.
180  */
181 int MSG_process_get_PID(m_process_t process)
182 {
183   xbt_assert0(((process != NULL) && (process->simdata)), "Invalid parameters");
184
185   return (((simdata_process_t) process->simdata)->PID);
186 }
187
188 /** \ingroup m_process_management
189  * \brief Returns the process ID of the parent of \a process.
190  *
191  * This functions checks whether \a process is a valid pointer or not 
192    and return its PID. Returns -1 if the agent has not been created by 
193    another agent.
194  */
195 int MSG_process_get_PPID(m_process_t process)
196 {
197   xbt_assert0(((process != NULL) && (process->simdata)), "Invalid parameters");
198
199   return (((simdata_process_t) process->simdata)->PPID);
200 }
201
202 /** \ingroup m_process_management
203  * \brief Return the name of an agent.
204  *
205  * This functions checks whether \a process is a valid pointer or not 
206    and return its name.
207  */
208 const char *MSG_process_get_name(m_process_t process)
209 {
210   xbt_assert0(((process != NULL) && (process->simdata)), "Invalid parameters");
211
212   return (process->name);
213 }
214
215 /** \ingroup m_process_management
216  * \brief Return the PID of the current agent.
217  *
218  * This functions returns the PID of the currently running #m_process_t.
219  */
220 int MSG_process_self_PID(void)
221 {
222   return (MSG_process_get_PID(MSG_process_self()));
223 }
224
225 /** \ingroup m_process_management
226  * \brief Return the PPID of the current agent.
227  *
228  * This functions returns the PID of the parent of the currently
229  * running #m_process_t.
230  */
231 int MSG_process_self_PPID(void)
232 {
233   return (MSG_process_get_PPID(MSG_process_self()));
234 }
235
236 /** \ingroup m_process_management
237  * \brief Return the current agent.
238  *
239  * This functions returns the currently running #m_process_t.
240  */
241 m_process_t MSG_process_self(void)
242 {
243         return (m_process_t)SIMIX_process_self()->data;
244 }
245
246 /** \ingroup m_process_management
247  * \brief Suspend the process.
248  *
249  * This functions suspend the process by suspending the task on which
250  * it was waiting for the completion.
251  */
252 MSG_error_t MSG_process_suspend(m_process_t process)
253 {
254         xbt_die("not implemented yet");
255         return MSG_OK;
256 }
257
258 /** \ingroup m_process_management
259  * \brief Resume a suspended process.
260  *
261  * This functions resume a suspended process by resuming the task on
262  * which it was waiting for the completion.
263  */
264 MSG_error_t MSG_process_resume(m_process_t process)
265 {
266         xbt_die("not implemented yet");
267         MSG_RETURN(MSG_OK);
268 }
269
270 /** \ingroup m_process_management
271  * \brief Returns true if the process is suspended .
272  *
273  * This checks whether a process is suspended or not by inspecting the
274  * task on which it was waiting for the completion.
275  */
276 int MSG_process_is_suspended(m_process_t process)
277 {
278         xbt_die("not implemented yet");
279         return 0;
280 }
281
282 int __MSG_process_block(double max_duration, const char *info)
283 {
284     return 1;
285 }
286
287 MSG_error_t __MSG_process_unblock(m_process_t process)
288 {
289     MSG_RETURN(MSG_OK);
290 }
291
292 int __MSG_process_isBlocked(m_process_t process)
293 {
294         return 0;
295 }