3 #include "xbt/sysdep.h"
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
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>.
18 /******************************** Process ************************************/
19 /** \ingroup m_process_management
20 * \brief Creates and runs a new #m_process_t.
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
26 m_process_t MSG_process_create(const char *name,
27 m_process_code_t code, void *data,
30 return MSG_process_create_with_arguments(name, code, data, host, -1, NULL);
33 static void MSG_process_cleanup(void *arg)
35 xbt_die("not implemented yet");
39 /** \ingroup m_process_management
40 * \brief Creates and runs a new #m_process_t.
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
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
61 * \return The new corresponding object.
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)
67 simdata_process_t simdata = xbt_new0(s_simdata_process_t,1);
68 m_process_t process = xbt_new0(s_m_process_t,1);
70 xbt_assert0(((code != NULL) && (host != NULL)), "Invalid parameters");
73 simdata->PID = msg_global->PID++;
77 simdata->smx_process = SIMIX_process_create_with_arguments(name, (smx_process_code_t)code,
78 (void*)process, host->simdata->host, argc, argv );
80 if (SIMIX_process_self()) {
81 simdata->PPID = MSG_process_get_PID(SIMIX_process_self()->data);
83 else simdata->PPID = -1;
84 simdata->last_errno=MSG_OK;
87 /* Process structure */
88 process->name = xbt_strdup(name);
89 process->simdata = simdata;
95 /** \ingroup m_process_management
96 * \param process poor victim
98 * This function simply kills a \a process... scarry isn't it ? :)
100 void MSG_process_kill(m_process_t process)
102 xbt_die("not implemented yet");
106 /** \ingroup m_process_management
107 * \brief Migrates an agent to another location.
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.
112 MSG_error_t MSG_process_change_host(m_process_t process, m_host_t host)
114 xbt_die("not implemented yet");
118 /** \ingroup m_process_management
119 * \brief Return the user data of a #m_process_t.
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.
124 void *MSG_process_get_data(m_process_t process)
126 xbt_assert0((process != NULL), "Invalid parameters");
128 return (process->data);
131 /** \ingroup m_process_management
132 * \brief Set the user data of a #m_process_t.
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.
137 MSG_error_t MSG_process_set_data(m_process_t process,void *data)
139 xbt_assert0((process != NULL), "Invalid parameters");
140 xbt_assert0((process->data == NULL), "Data already set");
142 process->data = data;
147 /** \ingroup m_process_management
148 * \brief Return the location on which an agent is running.
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
154 m_host_t MSG_process_get_host(m_process_t process)
156 xbt_assert0(((process != NULL) && (process->simdata)), "Invalid parameters");
158 return (((simdata_process_t) process->simdata)->host);
161 /** \ingroup m_process_management
163 * \brief Return a #m_process_t given its PID.
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.
169 m_process_t MSG_process_from_PID(int PID)
175 /** \ingroup m_process_management
176 * \brief Returns the process ID of \a process.
178 * This functions checks whether \a process is a valid pointer or not
181 int MSG_process_get_PID(m_process_t process)
183 xbt_assert0(((process != NULL) && (process->simdata)), "Invalid parameters");
185 return (((simdata_process_t) process->simdata)->PID);
188 /** \ingroup m_process_management
189 * \brief Returns the process ID of the parent of \a process.
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
195 int MSG_process_get_PPID(m_process_t process)
197 xbt_assert0(((process != NULL) && (process->simdata)), "Invalid parameters");
199 return (((simdata_process_t) process->simdata)->PPID);
202 /** \ingroup m_process_management
203 * \brief Return the name of an agent.
205 * This functions checks whether \a process is a valid pointer or not
208 const char *MSG_process_get_name(m_process_t process)
210 xbt_assert0(((process != NULL) && (process->simdata)), "Invalid parameters");
212 return (process->name);
215 /** \ingroup m_process_management
216 * \brief Return the PID of the current agent.
218 * This functions returns the PID of the currently running #m_process_t.
220 int MSG_process_self_PID(void)
222 return (MSG_process_get_PID(MSG_process_self()));
225 /** \ingroup m_process_management
226 * \brief Return the PPID of the current agent.
228 * This functions returns the PID of the parent of the currently
229 * running #m_process_t.
231 int MSG_process_self_PPID(void)
233 return (MSG_process_get_PPID(MSG_process_self()));
236 /** \ingroup m_process_management
237 * \brief Return the current agent.
239 * This functions returns the currently running #m_process_t.
241 m_process_t MSG_process_self(void)
243 return (m_process_t)SIMIX_process_self()->data;
246 /** \ingroup m_process_management
247 * \brief Suspend the process.
249 * This functions suspend the process by suspending the task on which
250 * it was waiting for the completion.
252 MSG_error_t MSG_process_suspend(m_process_t process)
254 xbt_die("not implemented yet");
258 /** \ingroup m_process_management
259 * \brief Resume a suspended process.
261 * This functions resume a suspended process by resuming the task on
262 * which it was waiting for the completion.
264 MSG_error_t MSG_process_resume(m_process_t process)
266 xbt_die("not implemented yet");
270 /** \ingroup m_process_management
271 * \brief Returns true if the process is suspended .
273 * This checks whether a process is suspended or not by inspecting the
274 * task on which it was waiting for the completion.
276 int MSG_process_is_suspended(m_process_t process)
278 xbt_die("not implemented yet");
282 int __MSG_process_block(double max_duration, const char *info)
287 MSG_error_t __MSG_process_unblock(m_process_t process)
292 int __MSG_process_isBlocked(m_process_t process)