Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Make it possible to have an empty profile callback.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Fri, 25 Mar 2022 08:36:50 +0000 (09:36 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Fri, 25 Mar 2022 09:07:16 +0000 (10:07 +0100)
src/kernel/resource/profile/Profile.cpp
src/kernel/resource/profile/Profile.hpp
src/kernel/resource/profile/ProfileBuilder.cpp

index 0f17aa7..a00d6bc 100644 (file)
@@ -38,14 +38,11 @@ Event* Profile::schedule(FutureEvtSet* fes, resource::Resource* resource)
 
   fes_ = fes;
 
-  if(event_list.empty())
-    cb(event_list);
-
-  if(event_list.empty()) {
+  if (get_enough_events(0)) {
+    fes_->add_event(event_list[0].date_, event);
+  } else {
     event->free_me  = true;
     tmgr_trace_event_unref(&event);
-  } else {
-    fes_->add_event(event_list[0].date_, event);
   }
   return event;
 }
@@ -59,15 +56,13 @@ DatedValue Profile::next(Event* event)
 
   event->idx++;
 
-  if (event->idx == event_list.size())
-    cb(event_list);
-  if(event->idx>=event_list.size())
-    event->free_me = true;
-  else {
-    const DatedValue& nextDateVal = event_list.at(event->idx);
+  if (get_enough_events(event->idx)) {
+    const DatedValue& nextDateVal = event_list[event->idx];
     xbt_assert(nextDateVal.date_>=0);
     xbt_assert(nextDateVal.value_>=0);
     fes_->add_event(event_date +nextDateVal.date_, event);
+  } else {
+    event->free_me = true;
   }
   return dateVal;
 }
@@ -77,7 +72,7 @@ Profile::Profile(const std::string& name, const std::function<ProfileBuilder::Up
 {
   xbt_assert(trace_list.find(name) == trace_list.end(), "Refusing to define trace %s twice", name.c_str());
   trace_list.insert({name,this});
-  cb(event_list);
+  get_enough_events(0);
 }
 
 } // namespace profile
index 9b9402a..5c51540 100644 (file)
@@ -54,6 +54,13 @@ private:
   std::vector<DatedValue> event_list;
   FutureEvtSet* fes_  = nullptr;
   double repeat_delay;
+
+  bool get_enough_events(size_t index)
+  {
+    if (index >= event_list.size() && cb)
+      cb(event_list);
+    return index < event_list.size();
+  }
 };
 
 } // namespace profile
index ba7a225..d7ba428 100644 (file)
@@ -237,7 +237,7 @@ Profile* ProfileBuilder::from_file(const std::string& path)
 
 
 Profile* ProfileBuilder::from_void() {
-  static Profile void_profile("__void__",[](std::vector<DatedValue>&){},-1.0);
+  static Profile void_profile("__void__", nullptr, -1.0);
   return &void_profile;
 }