Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
MSG/SIMIX Initial files. Only functions prototypes, not implemented yet.
[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         return;
36 }
37
38 /** \ingroup m_process_management
39  * \brief Creates and runs a new #m_process_t.
40
41  * A constructor for #m_process_t taking four arguments and returning the 
42  * corresponding object. The structure (and the corresponding thread) is
43  * created, and put in the list of ready process.
44  * \param name a name for the object. It is for user-level information
45    and can be NULL.
46  * \param code is a function describing the behavior of the agent. It
47    should then only use functions described in \ref
48    m_process_management (to create a new #m_process_t for example),
49    in \ref m_host_management (only the read-only functions i.e. whose
50    name contains the word get), in \ref m_task_management (to create
51    or destroy some #m_task_t for example) and in \ref
52    msg_gos_functions (to handle file transfers and task processing).
53  * \param data a pointer to any data one may want to attach to the new
54    object.  It is for user-level information and can be NULL. It can
55    be retrieved with the function \ref MSG_process_get_data.
56  * \param host the location where the new agent is executed.
57  * \param argc first argument passed to \a code
58  * \param argv second argument passed to \a code
59  * \see m_process_t
60  * \return The new corresponding object.
61  */
62 m_process_t MSG_process_create_with_arguments(const char *name,
63                                               m_process_code_t code, void *data,
64                                               m_host_t host, int argc, char **argv)
65 {
66   m_process_t process = xbt_new0(s_m_process_t,1);
67    return process;
68 }
69
70 /** \ingroup m_process_management
71  * \param process poor victim
72  *
73  * This function simply kills a \a process... scarry isn't it ? :)
74  */
75 void MSG_process_kill(m_process_t process)
76 {
77         return;
78 }
79
80 /** \ingroup m_process_management
81  * \brief Migrates an agent to another location.
82  *
83  * This functions checks whether \a process and \a host are valid pointers
84    and change the value of the #m_host_t on which \a process is running.
85  */
86 MSG_error_t MSG_process_change_host(m_process_t process, m_host_t host)
87 {
88   return MSG_OK;
89 }
90
91 /** \ingroup m_process_management
92  * \brief Return the user data of a #m_process_t.
93  *
94  * This functions checks whether \a process is a valid pointer or not 
95    and return the user data associated to \a process if it is possible.
96  */
97 void *MSG_process_get_data(m_process_t process)
98 {
99   xbt_assert0((process != NULL), "Invalid parameters");
100
101   return (process->data);
102 }
103
104 /** \ingroup m_process_management
105  * \brief Set the user data of a #m_process_t.
106  *
107  * This functions checks whether \a process is a valid pointer or not 
108    and set the user data associated to \a process if it is possible.
109  */
110 MSG_error_t MSG_process_set_data(m_process_t process,void *data)
111 {
112   xbt_assert0((process != NULL), "Invalid parameters");
113   xbt_assert0((process->data == NULL), "Data already set");
114   
115   process->data = data;
116    
117   return MSG_OK;
118 }
119
120 /** \ingroup m_process_management
121  * \brief Return the location on which an agent is running.
122  *
123  * This functions checks whether \a process is a valid pointer or not 
124    and return the m_host_t corresponding to the location on which \a 
125    process is running.
126  */
127 m_host_t MSG_process_get_host(m_process_t process)
128 {
129   xbt_assert0(((process != NULL) && (process->simdata)), "Invalid parameters");
130
131   return (((simdata_process_t) process->simdata)->host);
132 }
133
134 /** \ingroup m_process_management
135  *
136  * \brief Return a #m_process_t given its PID.
137  *
138  * This functions search in the list of all the created m_process_t for a m_process_t 
139    whose PID is equal to \a PID. If no host is found, \c NULL is returned. 
140    Note that the PID are uniq in the whole simulation, not only on a given host.
141  */
142 m_process_t MSG_process_from_PID(int PID)
143 {
144
145   return NULL;
146 }
147
148 /** \ingroup m_process_management
149  * \brief Returns the process ID of \a process.
150  *
151  * This functions checks whether \a process is a valid pointer or not 
152    and return its PID.
153  */
154 int MSG_process_get_PID(m_process_t process)
155 {
156   xbt_assert0(((process != NULL) && (process->simdata)), "Invalid parameters");
157
158   return (((simdata_process_t) process->simdata)->PID);
159 }
160
161 /** \ingroup m_process_management
162  * \brief Returns the process ID of the parent of \a process.
163  *
164  * This functions checks whether \a process is a valid pointer or not 
165    and return its PID. Returns -1 if the agent has not been created by 
166    another agent.
167  */
168 int MSG_process_get_PPID(m_process_t process)
169 {
170   xbt_assert0(((process != NULL) && (process->simdata)), "Invalid parameters");
171
172   return (((simdata_process_t) process->simdata)->PPID);
173 }
174
175 /** \ingroup m_process_management
176  * \brief Return the name of an agent.
177  *
178  * This functions checks whether \a process is a valid pointer or not 
179    and return its name.
180  */
181 const char *MSG_process_get_name(m_process_t process)
182 {
183   xbt_assert0(((process != NULL) && (process->simdata)), "Invalid parameters");
184
185   return (process->name);
186 }
187
188 /** \ingroup m_process_management
189  * \brief Return the PID of the current agent.
190  *
191  * This functions returns the PID of the currently running #m_process_t.
192  */
193 int MSG_process_self_PID(void)
194 {
195   return (MSG_process_get_PID(MSG_process_self()));
196 }
197
198 /** \ingroup m_process_management
199  * \brief Return the PPID of the current agent.
200  *
201  * This functions returns the PID of the parent of the currently
202  * running #m_process_t.
203  */
204 int MSG_process_self_PPID(void)
205 {
206   return (MSG_process_get_PPID(MSG_process_self()));
207 }
208
209 /** \ingroup m_process_management
210  * \brief Return the current agent.
211  *
212  * This functions returns the currently running #m_process_t.
213  */
214 m_process_t MSG_process_self(void)
215 {
216         return NULL;
217 }
218
219 /** \ingroup m_process_management
220  * \brief Suspend the process.
221  *
222  * This functions suspend the process by suspending the task on which
223  * it was waiting for the completion.
224  */
225 MSG_error_t MSG_process_suspend(m_process_t process)
226 {
227    return MSG_OK;
228 }
229
230 /** \ingroup m_process_management
231  * \brief Resume a suspended process.
232  *
233  * This functions resume a suspended process by resuming the task on
234  * which it was waiting for the completion.
235  */
236 MSG_error_t MSG_process_resume(m_process_t process)
237 {
238         MSG_RETURN(MSG_OK);
239 }
240
241 /** \ingroup m_process_management
242  * \brief Returns true if the process is suspended .
243  *
244  * This checks whether a process is suspended or not by inspecting the
245  * task on which it was waiting for the completion.
246  */
247 int MSG_process_is_suspended(m_process_t process)
248 {
249  return 0;
250 }
251
252 int __MSG_process_block(double max_duration, const char *info)
253 {
254     return 1;
255 }
256
257 MSG_error_t __MSG_process_unblock(m_process_t process)
258 {
259     MSG_RETURN(MSG_OK);
260 }
261
262 int __MSG_process_isBlocked(m_process_t process)
263 {
264         return 0;
265 }