+/** \brief Creates a new SIMIX action to communicate two hosts.
+ *
+ * This function creates a SURF action and allocates the data necessary to create the SIMIX action. It can raise a network_error exception if the host is unavailable.
+ * \param sender SIMIX host sender
+ * \param receiver SIMIX host receiver
+ * \param name Action name
+ * \param size Communication size (in bytes)
+ * \param rate Communication rate between hosts.
+ * \return A new SIMIX action
+ * */
+smx_action_t SIMIX_action_communicate(smx_host_t sender,
+ smx_host_t receiver, const char *name,
+ double size, double rate)
+{
+ smx_action_t act;
+
+ /* check if the host is active */
+ if (surf_workstation_model->extension.workstation.get_state(sender->host) !=
+ SURF_RESOURCE_ON) {
+ THROW1(network_error, 0, "Host %s failed, you cannot call this function",
+ sender->name);
+ }
+ if (surf_workstation_model->extension.workstation.
+ get_state(receiver->host) != SURF_RESOURCE_ON) {
+ THROW1(network_error, 0, "Host %s failed, you cannot call this function",
+ receiver->name);
+ }
+
+ /* alloc structures */
+ act = xbt_new0(s_smx_action_t, 1);
+ act->cond_list = xbt_fifo_new();
+ act->sem_list = xbt_fifo_new();
+
+ /* initialize them */
+ act->name = xbt_strdup(name);
+ act->source = sender;
+#ifdef HAVE_TRACING
+ act->category = NULL;
+#endif
+
+ act->surf_action =
+ surf_workstation_model->extension.workstation.communicate(sender->host,
+ receiver->host,
+ size, rate);
+ surf_workstation_model->action_data_set(act->surf_action, act);
+
+ DEBUG1("Create communicate action %p", act);
+ return act;
+}
+
+/** \brief Creates a new SIMIX action to execute an action.
+ *
+ * This function creates a SURF action and allocates the data necessary to create the SIMIX action. It can raise a host_error exception if the host crashed.
+ * \param host SIMIX host where the action will be executed
+ * \param name Action name
+ * \param amount Task amount (in bytes)
+ * \return A new SIMIX action
+ * */
+smx_action_t SIMIX_action_execute(smx_host_t host, const char *name,
+ double amount)
+{
+ smx_action_t act;
+
+ /* check if the host is active */
+ if (surf_workstation_model->extension.workstation.get_state(host->host) !=
+ SURF_RESOURCE_ON) {
+ THROW1(host_error, 0, "Host %s failed, you cannot call this function",
+ host->name);
+ }
+
+ /* alloc structures */
+ act = xbt_new0(s_smx_action_t, 1);
+ act->cond_list = xbt_fifo_new();
+ act->sem_list = xbt_fifo_new();
+
+ /* initialize them */
+ act->source = host;
+ act->name = xbt_strdup(name);
+#ifdef HAVE_TRACING
+ act->category = NULL;
+#endif
+
+ /* set communication */
+ act->surf_action =
+ surf_workstation_model->extension.workstation.execute(host->host, amount);
+
+ surf_workstation_model->action_data_set(act->surf_action, act);
+
+ DEBUG1("Create execute action %p", act);
+#ifdef HAVE_TRACING
+ TRACE_smx_action_execute (act);
+#endif
+ return act;
+}
+
+/** \brief Creates a new sleep SIMIX action.
+ *
+ * This function creates a SURF action and allocates the data necessary
+ * to create the SIMIX action. It can raise a host_error exception if the
+ * host crashed. The default SIMIX name of the action is "sleep".
+ *
+ * \param host SIMIX host where the sleep will run.
+ * \param duration Time duration of the sleep.
+ * \return A new SIMIX action
+ * */
+smx_action_t SIMIX_action_sleep(smx_host_t host, double duration)
+{
+ char name[] = "sleep";
+ smx_action_t act;
+
+ /* check if the host is active */
+ if (surf_workstation_model->extension.workstation.get_state(host->host) !=
+ SURF_RESOURCE_ON) {
+ THROW1(host_error, 0, "Host %s failed, you cannot call this function",
+ host->name);
+ }
+
+ /* alloc structures */
+ act = xbt_new0(s_smx_action_t, 1);
+ act->cond_list = xbt_fifo_new();
+ act->sem_list = xbt_fifo_new();
+
+ /* initialize them */
+ act->source = host;
+ act->name = xbt_strdup(name);
+#ifdef HAVE_TRACING
+ act->category = NULL;
+#endif
+
+ act->surf_action =
+ surf_workstation_model->extension.workstation.sleep(host->host, duration);
+
+ surf_workstation_model->action_data_set(act->surf_action, act);
+
+ DEBUG1("Create sleep action %p", act);
+ return act;
+}
+
+/**
+ * \brief Cancels an action.
+ *
+ * This functions stops the execution of an action. It calls a surf functions.
+ * \param action The SIMIX action
+ */
+XBT_INLINE void SIMIX_action_cancel(smx_action_t action)
+{
+ xbt_assert0((action != NULL), "Invalid parameter");
+
+ DEBUG1("Cancel action %p", action);
+ if (action->surf_action) {
+ surf_workstation_model->action_cancel(action->surf_action);
+ }
+ return;
+}
+
+/**
+ * \brief Changes the action's priority
+ *
+ * This functions changes the priority only. It calls a surf functions.
+ * \param action The SIMIX action
+ * \param priority The new priority
+ */
+XBT_INLINE void SIMIX_action_set_priority(smx_action_t action, double priority)
+{
+ xbt_assert0((action != NULL), "Invalid parameter");
+
+ surf_workstation_model->set_priority(action->surf_action, priority);
+ return;
+}
+
+/**
+ * \brief Resumes the execution of an action.
+ *
+ * This functions restarts the execution of an action. It just calls the right SURF function.
+ * \param action The SIMIX action
+ * \param priority The new priority
+ */
+XBT_INLINE void SIMIX_action_resume(smx_action_t action)
+{
+ xbt_assert0((action != NULL), "Invalid parameter");
+
+ surf_workstation_model->resume(action->surf_action);
+ return;
+}
+
+/**
+ * \brief Suspends the execution of an action.
+ *
+ * This functions suspends the execution of an action. It just calls the right SURF function.
+ * \param action The SIMIX action
+ * \param priority The new priority
+ */
+XBT_INLINE void SIMIX_action_suspend(smx_action_t action)
+{
+ xbt_assert0((action != NULL), "Invalid parameter");
+
+ surf_workstation_model->suspend(action->surf_action);
+ return;
+}
+
+/**
+ * \brief Destroys an action
+ *
+ * Destroys an action, freing its memory. This function cannot be called if there are a conditional waiting for it.
+ * \param action The SIMIX action
+ */
+int SIMIX_action_destroy(smx_action_t action)
+{
+ XBT_IN3("(%p:'%s',%d)", action, action->name, action->refcount);
+ xbt_assert0((action != NULL), "Invalid parameter");
+
+ action->refcount--;
+ if (action->refcount > 0)
+ return 0;
+
+ xbt_assert1((xbt_fifo_size(action->cond_list) == 0),
+ "Conditional list not empty %d. There is a problem. Cannot destroy it now!",
+ xbt_fifo_size(action->cond_list));
+
+ xbt_assert1((xbt_fifo_size(action->sem_list) == 0),
+ "Semaphore list not empty %d. There is a problem. Cannot destroy it now!",
+ xbt_fifo_size(action->sem_list));
+
+ DEBUG1("Destroy action %p", action);
+ if (action->name)
+ xbt_free(action->name);
+
+ xbt_fifo_free(action->cond_list);
+ xbt_fifo_free(action->sem_list);
+
+ if (action->surf_action)
+ action->surf_action->model_type->action_unref(action->surf_action);
+#ifdef HAVE_TRACING
+ TRACE_smx_action_destroy (action);
+#endif
+ xbt_free(action);
+ return 1;
+}