Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
C++ify some forgotten part of surf
authorMartin Quinson <martin.quinson@loria.fr>
Sun, 8 Jul 2018 09:24:24 +0000 (11:24 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Sun, 8 Jul 2018 09:24:24 +0000 (11:24 +0200)
include/simgrid/kernel/resource/Model.hpp
src/include/surf/surf.hpp
src/kernel/resource/Model.cpp
src/simdag/sd_global.cpp
src/simix/smx_global.cpp
src/surf/surf_c_bindings.cpp
teshsuite/surf/surf_usage2/surf_usage2.cpp

index 59a0cce..ce391af 100644 (file)
@@ -71,6 +71,13 @@ public:
   virtual double next_occuring_event_lazy(double now);
   virtual double next_occuring_event_full(double now);
 
+private:
+  Action* extract_action(Action::StateSet* list);
+
+public:
+  Action* extract_done_action();
+  Action* extract_failed_action();
+
   /**
    * @brief Update action to the current time
    *
index 3abcc8d..7fb194e 100644 (file)
 
 /** @{ @ingroup SURF_c_bindings */
 
-/**
- * @brief Pop an action from the done actions set
- *
- * @param model The model from which the action is extracted
- * @return An action in done state
- */
-XBT_PUBLIC simgrid::kernel::resource::Action*
-surf_model_extract_done_action_set(simgrid::kernel::resource::Model* model);
-
-/**
- * @brief Pop an action from the failed actions set
- *
- * @param model The model from which the action is extracted
- * @return An action in failed state
- */
-XBT_PUBLIC simgrid::kernel::resource::Action*
-surf_model_extract_failed_action_set(simgrid::kernel::resource::Model* model);
-
 /**
  * @brief Get the size of the running action set of a model
  *
index 65c0350..d7c6645 100644 (file)
@@ -141,6 +141,28 @@ void Model::update_actions_state(double now, double delta)
     xbt_die("Invalid cpu update mechanism!");
 }
 
+/** Pops and returns the first action of that state set (or nullptr if none exist) */
+Action* Model::extract_action(Action::StateSet* list)
+{
+  if (list->empty())
+    return nullptr;
+  simgrid::kernel::resource::Action* res = &list->front();
+  list->pop_front();
+  return res;
+}
+
+/** Pops and returns the first finished action (or nullptr if none exist) */
+Action* Model::extract_done_action()
+{
+  return extract_action(get_finished_action_set());
+}
+
+/** Pops and returns the failed finished action (or nullptr if none exist) */
+Action* Model::extract_failed_action()
+{
+  return extract_action(get_failed_action_set());
+}
+
 void Model::update_actions_state_lazy(double /*now*/, double /*delta*/)
 {
   THROW_UNIMPLEMENTED;
index 7a2b1a9..193b5f4 100644 (file)
@@ -57,7 +57,7 @@ std::set<SD_task_t>* simulate(double how_long){
 
     /* let's see which tasks are done */
     for (auto const& model : *all_existing_models) {
-      simgrid::kernel::resource::Action* action = surf_model_extract_done_action_set(model);
+      simgrid::kernel::resource::Action* action = model->extract_done_action();
       while (action != nullptr && action->get_data() != nullptr) {
         SD_task_t task = static_cast<SD_task_t>(action->get_data());
         XBT_VERB("Task '%s' done", SD_task_get_name(task));
@@ -103,17 +103,17 @@ std::set<SD_task_t>* simulate(double how_long){
             SD_task_run(output);
         }
         task->outputs->clear();
-        action = surf_model_extract_done_action_set(model);
+        action = model->extract_done_action();
       }
 
       /* let's see which tasks have just failed */
-      action = surf_model_extract_failed_action_set(model);
+      action = model->extract_failed_action();
       while (action != nullptr) {
         SD_task_t task = static_cast<SD_task_t>(action->get_data());
         XBT_VERB("Task '%s' failed", SD_task_get_name(task));
         SD_task_set_state(task, SD_FAILED);
         sd_global->return_set->insert(task);
-        action = surf_model_extract_failed_action_set(model);
+        action = model->extract_failed_action();
       }
     }
   }
index 6e7b575..4a1b82a 100644 (file)
@@ -311,12 +311,12 @@ static void SIMIX_wake_processes()
     simgrid::kernel::resource::Action* action;
 
     XBT_DEBUG("Handling the processes whose action failed (if any)");
-    while ((action = surf_model_extract_failed_action_set(model))) {
+    while ((action = model->extract_failed_action())) {
       XBT_DEBUG("   Handling Action %p",action);
       SIMIX_simcall_exit(static_cast<simgrid::kernel::activity::ActivityImpl*>(action->get_data()));
     }
     XBT_DEBUG("Handling the processes whose action terminated normally (if any)");
-    while ((action = surf_model_extract_done_action_set(model))) {
+    while ((action = model->extract_done_action())) {
       XBT_DEBUG("   Handling Action %p",action);
       if (action->get_data() == nullptr)
         XBT_DEBUG("probably vcpu's action %p, skip", action);
index 07e3030..22f7a3a 100644 (file)
@@ -152,25 +152,6 @@ double surf_solve(double max_date)
 /*********
  * MODEL *
  *********/
-static simgrid::kernel::resource::Action* ActionListExtract(simgrid::kernel::resource::Action::StateSet* list)
-{
-  if (list->empty())
-    return nullptr;
-  simgrid::kernel::resource::Action* res = &list->front();
-  list->pop_front();
-  return res;
-}
-
-simgrid::kernel::resource::Action* surf_model_extract_done_action_set(simgrid::kernel::resource::Model* model)
-{
-  return ActionListExtract(model->get_finished_action_set());
-}
-
-simgrid::kernel::resource::Action* surf_model_extract_failed_action_set(simgrid::kernel::resource::Model* model)
-{
-  return ActionListExtract(model->get_failed_action_set());
-}
-
 int surf_model_running_action_set_size(simgrid::kernel::resource::Model* model)
 {
   return model->get_started_action_set()->size();
index 9ddc811..c1ab1b9 100644 (file)
@@ -51,20 +51,20 @@ int main(int argc, char **argv)
         running = 1;
       }
 
-      action = surf_model_extract_failed_action_set(model);
+      action = model->extract_failed_action();
       while (action != nullptr) {
         XBT_INFO("   * Done Action");
         XBT_DEBUG("\t * Failed Action: %p", action);
         action->unref();
-        action = surf_model_extract_failed_action_set(model);
+        action = model->extract_failed_action();
       }
 
-      action = surf_model_extract_done_action_set(model);
+      action = model->extract_done_action();
       while (action != nullptr){
         XBT_INFO("   * Done Action");
         XBT_DEBUG("\t * Done Action: %p", action);
         action->unref();
-        action = surf_model_extract_done_action_set(model);
+        action = model->extract_done_action();
       }
     }
   } while (running && surf_solve(-1.0) >= 0.0);