3 /* Copyright (c) 2002,2003,2004 Arnaud Legrand. All rights reserved. */
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. */
10 #include "xbt/error.h"
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(task, msg,
12 "Logging specific to MSG (task)");
14 static char sprint_buffer[64];
16 /********************************* Task **************************************/
17 /** \ingroup m_task_management
18 * \brief Creates a new #m_task_t.
20 * A constructor for #m_task_t taking four arguments and returning the
22 * \param name a name for the object. It is for user-level information
24 * \param compute_duration a value of the processing amount (in Mflop)
25 needed to process this new task. If 0, then it cannot be executed with
26 MSG_task_execute(). This value has to be >=0.
27 * \param message_size a value of the amount of data (in Mb) needed to
28 transfer this new task. If 0, then it cannot be transfered with
29 MSG_task_get() and MSG_task_put(). This value has to be >=0.
30 * \param data a pointer to any data may want to attach to the new
31 object. It is for user-level information and can be NULL. It can
32 be retrieved with the function \ref MSG_task_get_data.
34 * \return The new corresponding object.
36 m_task_t MSG_task_create(const char *name, long double compute_duration,
37 long double message_size, void *data)
39 simdata_task_t simdata = xbt_new0(s_simdata_task_t,1);
40 m_task_t task = xbt_new0(s_m_task_t,1);
43 task->name = xbt_strdup(name);
44 task->simdata = simdata;
48 simdata->sleeping = xbt_dynar_new(sizeof(m_process_t),NULL);
49 simdata->computation_amount = compute_duration;
50 simdata->message_size = message_size;
53 simdata->sender = NULL;
59 /** \ingroup m_task_management
60 * \brief Return the user data of a #m_task_t.
62 * This functions checks whether \a task is a valid pointer or not and return
63 the user data associated to \a task if it is possible.
65 void *MSG_task_get_data(m_task_t task)
67 xbt_assert0((task != NULL), "Invalid parameter");
72 /** \ingroup m_task_management
73 * \brief Return the sender of a #m_task_t.
75 * This functions returns the #m_process_t which sent this task
77 m_process_t MSG_task_get_sender(m_task_t task)
79 xbt_assert0(task, "Invalid parameters");
80 return ((simdata_task_t) task->simdata)->sender;
84 /** \ingroup m_task_management
85 * \brief Destroy a #m_task_t.
87 * Destructor for #m_task_t. Note that you should free user data, if any, \b
88 before calling this function.
90 MSG_error_t MSG_task_destroy(m_task_t task)
92 simdata_task_t simdata = NULL;
93 surf_action_t action = NULL;
96 xbt_assert0((task != NULL), "Invalid parameter");
98 task->simdata->using--;
99 if(task->simdata->using>0) return MSG_OK;
101 xbt_assert0((xbt_dynar_length(task->simdata->sleeping)==0),
102 "Task still used. There is a problem. Cannot destroy it now!");
104 if(task->name) xbt_free(task->name);
106 xbt_dynar_free(&(task->simdata->sleeping));
108 action = task->simdata->compute;
109 if(action) action->resource_type->common_public->action_free(action);
110 action = task->simdata->comm;
111 if(action) action->resource_type->common_public->action_free(action);
114 xbt_free(task->simdata);
120 /* static MSG_error_t __MSG_task_check(m_task_t task) */
122 /* simdata_task_t simdata = NULL; */
123 /* int warning = 0; */
125 /* if (task == NULL) { /\* Fatal *\/ */
126 /* WARNING("Task uninitialized"); */
127 /* return MSG_FATAL; */
129 /* simdata = task->simdata; */
131 /* if (simdata == NULL) { /\* Fatal *\/ */
132 /* WARNING("Simulator Data uninitialized"); */
133 /* return MSG_FATAL; */
136 /* if (simdata->compute == NULL) { /\* Fatal if execute ... *\/ */
137 /* WARNING("No duration set for this task"); */
141 /* if (simdata->message_size == 0) { /\* Fatal if transfered ... *\/ */
142 /* WARNING("No message_size set for this task"); */
146 /* /\* if (task->data == NULL) { *\/ */
147 /* /\* WARNING("User Data uninitialized"); *\/ */
148 /* /\* warning++; *\/ */
152 /* return MSG_WARNING; */
156 /* static m_task_t __MSG_task_copy(m_task_t src) */
158 /* m_task_t copy = NULL; */
159 /* simdata_task_t simdata = NULL; */
161 /* __MSG_task_check(src); */
163 /* simdata = src->simdata; */
164 /* copy = MSG_task_create(src->name, SG_getTaskCost(simdata->compute), */
165 /* simdata->message_size, MSG_task_get_data(src)); */
170 MSG_error_t __MSG_task_wait_event(m_process_t process, m_task_t task)
173 m_process_t proc = NULL;
175 xbt_assert0(((task != NULL)
176 && (task->simdata != NULL)), "Invalid parameters");
178 xbt_dynar_push(task->simdata->sleeping, &process);
179 process->simdata->waiting_task = task;
181 process->simdata->waiting_task = NULL;
182 xbt_dynar_foreach(task->simdata->sleeping,_cursor,proc) {
184 xbt_dynar_remove_at(task->simdata->sleeping,_cursor,&proc);