Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Rename model methods action_use/free to action_ref/unref
[simgrid.git] / src / simix / smx_action.c
index 3be2dd5..310cad8 100644 (file)
@@ -16,7 +16,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_action, simix,
 /************************************* Actions *********************************/
 /** \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. 
+ *     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
@@ -32,13 +32,13 @@ smx_action_t SIMIX_action_communicate(smx_host_t sender,
   smx_simdata_action_t simdata;
 
   /* check if the host is active */
-  if (surf_workstation_model->
-      extension_public->get_state(sender->simdata->host) != SURF_CPU_ON) {
+  if (surf_workstation_model->extension.
+      workstation.get_state(sender->simdata->host) != SURF_CPU_ON) {
     THROW1(network_error, 0, "Host %s failed, you cannot call this function",
            sender->name);
   }
-  if (surf_workstation_model->
-      extension_public->get_state(receiver->simdata->host) != SURF_CPU_ON) {
+  if (surf_workstation_model->extension.
+      workstation.get_state(receiver->simdata->host) != SURF_CPU_ON) {
     THROW1(network_error, 0, "Host %s failed, you cannot call this function",
            receiver->name);
   }
@@ -55,12 +55,9 @@ smx_action_t SIMIX_action_communicate(smx_host_t sender,
 
 
   simdata->surf_action =
-    surf_workstation_model->extension_public->communicate(sender->simdata->
-                                                          host,
-                                                          receiver->simdata->
-                                                          host, size, rate);
-  surf_workstation_model->common_public->action_set_data(simdata->surf_action,
-                                                         act);
+    surf_workstation_model->extension.workstation.
+    communicate(sender->simdata->host, receiver->simdata->host, size, rate);
+  surf_workstation_model->action_data_set(simdata->surf_action, act);
 
   DEBUG1("Create communicate action %p", act);
   return act;
@@ -68,7 +65,7 @@ smx_action_t SIMIX_action_communicate(smx_host_t sender,
 
 /** \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. 
+ *     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)
@@ -81,8 +78,8 @@ smx_action_t SIMIX_action_execute(smx_host_t host, const char *name,
   smx_simdata_action_t simdata;
 
   /* check if the host is active */
-  if (surf_workstation_model->
-      extension_public->get_state(host->simdata->host) != SURF_CPU_ON) {
+  if (surf_workstation_model->extension.
+      workstation.get_state(host->simdata->host) != SURF_CPU_ON) {
     THROW1(host_error, 0, "Host %s failed, you cannot call this function",
            host->name);
   }
@@ -99,11 +96,10 @@ smx_action_t SIMIX_action_execute(smx_host_t host, const char *name,
 
   /* set communication */
   simdata->surf_action =
-    surf_workstation_model->extension_public->execute(host->simdata->host,
-                                                      amount);
+    surf_workstation_model->extension.workstation.execute(host->simdata->host,
+                                                          amount);
 
-  surf_workstation_model->common_public->action_set_data(simdata->surf_action,
-                                                         act);
+  surf_workstation_model->action_data_set(simdata->surf_action, act);
 
   DEBUG1("Create execute action %p", act);
   return act;
@@ -111,7 +107,7 @@ smx_action_t SIMIX_action_execute(smx_host_t host, const char *name,
 
 /** \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".  
+ *     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
@@ -123,8 +119,8 @@ smx_action_t SIMIX_action_sleep(smx_host_t host, double duration)
   smx_action_t act;
 
   /* check if the host is active */
-  if (surf_workstation_model->
-      extension_public->get_state(host->simdata->host) != SURF_CPU_ON) {
+  if (surf_workstation_model->extension.
+      workstation.get_state(host->simdata->host) != SURF_CPU_ON) {
     THROW1(host_error, 0, "Host %s failed, you cannot call this function",
            host->name);
   }
@@ -140,11 +136,10 @@ smx_action_t SIMIX_action_sleep(smx_host_t host, double duration)
   act->name = xbt_strdup(name);
 
   simdata->surf_action =
-    surf_workstation_model->extension_public->sleep(host->simdata->host,
-                                                    duration);
+    surf_workstation_model->extension.workstation.sleep(host->simdata->host,
+                                                        duration);
 
-  surf_workstation_model->common_public->action_set_data(simdata->surf_action,
-                                                         act);
+  surf_workstation_model->action_data_set(simdata->surf_action, act);
 
   DEBUG1("Create sleep action %p", act);
   return act;
@@ -162,8 +157,7 @@ void SIMIX_action_cancel(smx_action_t action)
 
   DEBUG1("Cancel action %p", action);
   if (action->simdata->surf_action) {
-    surf_workstation_model->common_public->action_cancel(action->
-                                                         simdata->surf_action);
+    surf_workstation_model->action_cancel(action->simdata->surf_action);
   }
   return;
 }
@@ -180,21 +174,26 @@ void SIMIX_action_set_priority(smx_action_t action, double priority)
   xbt_assert0((action != NULL)
               && (action->simdata != NULL), "Invalid parameter");
 
-  surf_workstation_model->common_public->set_priority(action->simdata->
-                                                      surf_action, priority);
+  surf_workstation_model->set_priority(action->simdata->surf_action,
+                                       priority);
   return;
 }
 
 /**
  *     \brief Destroys an action
  *
- *     Destroys an action, freing its memory. This function cannot be called if there are a conditional waiting for it. 
+ *     Destroys an action, freing its memory. This function cannot be called if there are a conditional waiting for it.
  *     \param action The SIMIX action
  */
-void SIMIX_action_destroy(smx_action_t 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));
@@ -206,18 +205,47 @@ void SIMIX_action_destroy(smx_action_t action)
   xbt_fifo_free(action->cond_list);
 
   if (action->simdata->surf_action)
-    action->simdata->surf_action->model_type->
-      common_public->action_free(action->simdata->surf_action);
+    action->simdata->surf_action->model_type->action_unref(action->
+                                                          simdata->surf_action);
 
   xbt_free(action->simdata);
   xbt_free(action);
+  return 1;
+}
+
+/**
+ *     \brief Increase refcount of anan action
+ *
+ *     \param action The SIMIX action
+ */
+void SIMIX_action_use(smx_action_t action)
+{
+  XBT_IN3("(%p:'%s',%d)", action, action->name, action->refcount);
+  xbt_assert0((action != NULL), "Invalid parameter");
+
+  action->refcount++;
+
+  return;
+}
+
+/**
+ *     \brief Decrease refcount of anan action
+ *
+ *     \param action The SIMIX action
+ */
+void SIMIX_action_release(smx_action_t action)
+{
+  xbt_assert0((action != NULL), "Invalid parameter");
+
+  action->refcount--;
+
   return;
 }
 
 /**
  *     \brief Set an action to a condition
  *
- *     Creates the "link" between an action and a condition. You have to call this function when you create an action and want to wait its ending. 
+ *     Creates the "link" between an action and a condition. You have to call this function when you create an action and want to wait its ending.
  *     \param action SIMIX action
  *     \param cond SIMIX cond
  */
@@ -294,15 +322,12 @@ smx_action_t SIMIX_action_parallel_execute(char *name, int host_nb,
     workstation_list[i] = host_list[i]->simdata->host;
 
   simdata->surf_action =
-    surf_workstation_model->extension_public->execute_parallel_task(host_nb,
-                                                                    workstation_list,
-                                                                    computation_amount,
-                                                                    communication_amount,
-                                                                    amount,
-                                                                    rate);
+    surf_workstation_model->extension.
+    workstation.execute_parallel_task(host_nb, workstation_list,
+                                      computation_amount,
+                                      communication_amount, amount, rate);
 
-  surf_workstation_model->common_public->action_set_data(simdata->surf_action,
-                                                         act);
+  surf_workstation_model->action_data_set(simdata->surf_action, act);
 
   return act;
 }
@@ -310,9 +335,8 @@ smx_action_t SIMIX_action_parallel_execute(char *name, int host_nb,
 e_surf_action_state_t SIMIX_action_get_state(smx_action_t action)
 {
   xbt_assert0((action != NULL), "Invalid parameter");
-  return surf_workstation_model->common_public->action_get_state(action->
-                                                                 simdata->
-                                                                 surf_action);
+  return surf_workstation_model->action_state_get(action->simdata->
+                                                  surf_action);
 
 }
 
@@ -323,7 +347,7 @@ void __SIMIX_cond_display_actions(smx_cond_t cond)
 
   DEBUG1("Actions for condition %p", cond);
   xbt_fifo_foreach(cond->actions, item, action, smx_action_t)
-    DEBUG1("\t %p", action);
+    DEBUG2("\t %p [%s]", action, action->name);
 }
 
 void __SIMIX_action_display_conditions(smx_action_t action)