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)
38 /** \ingroup m_process_management
39 * \brief Creates and runs a new #m_process_t.
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
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
60 * \return The new corresponding object.
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)
66 m_process_t process = xbt_new0(s_m_process_t,1);
70 /** \ingroup m_process_management
71 * \param process poor victim
73 * This function simply kills a \a process... scarry isn't it ? :)
75 void MSG_process_kill(m_process_t process)
80 /** \ingroup m_process_management
81 * \brief Migrates an agent to another location.
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.
86 MSG_error_t MSG_process_change_host(m_process_t process, m_host_t host)
91 /** \ingroup m_process_management
92 * \brief Return the user data of a #m_process_t.
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.
97 void *MSG_process_get_data(m_process_t process)
99 xbt_assert0((process != NULL), "Invalid parameters");
101 return (process->data);
104 /** \ingroup m_process_management
105 * \brief Set the user data of a #m_process_t.
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.
110 MSG_error_t MSG_process_set_data(m_process_t process,void *data)
112 xbt_assert0((process != NULL), "Invalid parameters");
113 xbt_assert0((process->data == NULL), "Data already set");
115 process->data = data;
120 /** \ingroup m_process_management
121 * \brief Return the location on which an agent is running.
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
127 m_host_t MSG_process_get_host(m_process_t process)
129 xbt_assert0(((process != NULL) && (process->simdata)), "Invalid parameters");
131 return (((simdata_process_t) process->simdata)->host);
134 /** \ingroup m_process_management
136 * \brief Return a #m_process_t given its PID.
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.
142 m_process_t MSG_process_from_PID(int PID)
148 /** \ingroup m_process_management
149 * \brief Returns the process ID of \a process.
151 * This functions checks whether \a process is a valid pointer or not
154 int MSG_process_get_PID(m_process_t process)
156 xbt_assert0(((process != NULL) && (process->simdata)), "Invalid parameters");
158 return (((simdata_process_t) process->simdata)->PID);
161 /** \ingroup m_process_management
162 * \brief Returns the process ID of the parent of \a process.
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
168 int MSG_process_get_PPID(m_process_t process)
170 xbt_assert0(((process != NULL) && (process->simdata)), "Invalid parameters");
172 return (((simdata_process_t) process->simdata)->PPID);
175 /** \ingroup m_process_management
176 * \brief Return the name of an agent.
178 * This functions checks whether \a process is a valid pointer or not
181 const char *MSG_process_get_name(m_process_t process)
183 xbt_assert0(((process != NULL) && (process->simdata)), "Invalid parameters");
185 return (process->name);
188 /** \ingroup m_process_management
189 * \brief Return the PID of the current agent.
191 * This functions returns the PID of the currently running #m_process_t.
193 int MSG_process_self_PID(void)
195 return (MSG_process_get_PID(MSG_process_self()));
198 /** \ingroup m_process_management
199 * \brief Return the PPID of the current agent.
201 * This functions returns the PID of the parent of the currently
202 * running #m_process_t.
204 int MSG_process_self_PPID(void)
206 return (MSG_process_get_PPID(MSG_process_self()));
209 /** \ingroup m_process_management
210 * \brief Return the current agent.
212 * This functions returns the currently running #m_process_t.
214 m_process_t MSG_process_self(void)
219 /** \ingroup m_process_management
220 * \brief Suspend the process.
222 * This functions suspend the process by suspending the task on which
223 * it was waiting for the completion.
225 MSG_error_t MSG_process_suspend(m_process_t process)
230 /** \ingroup m_process_management
231 * \brief Resume a suspended process.
233 * This functions resume a suspended process by resuming the task on
234 * which it was waiting for the completion.
236 MSG_error_t MSG_process_resume(m_process_t process)
241 /** \ingroup m_process_management
242 * \brief Returns true if the process is suspended .
244 * This checks whether a process is suspended or not by inspecting the
245 * task on which it was waiting for the completion.
247 int MSG_process_is_suspended(m_process_t process)
252 int __MSG_process_block(double max_duration, const char *info)
257 MSG_error_t __MSG_process_unblock(m_process_t process)
262 int __MSG_process_isBlocked(m_process_t process)