Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Define helper methods to access actionHeap_.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Sun, 12 Nov 2017 17:56:45 +0000 (18:56 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Sun, 12 Nov 2017 22:03:59 +0000 (23:03 +0100)
src/surf/cpu_interface.cpp
src/surf/cpu_ti.cpp
src/surf/network_cm02.cpp
src/surf/surf_interface.cpp
src/surf/surf_interface.hpp

index 044d58f..554c871 100644 (file)
@@ -23,10 +23,9 @@ namespace surf {
 
 void CpuModel::updateActionsStateLazy(double now, double /*delta*/)
 {
-  while ((xbt_heap_size(getActionHeap()) > 0)
-         && (double_equals(xbt_heap_maxkey(getActionHeap()), now, sg_surf_precision))) {
+  while (not actionHeapIsEmpty() && double_equals(actionHeapTopDate(), now, sg_surf_precision)) {
 
-    CpuAction *action = static_cast<CpuAction*>(xbt_heap_pop(getActionHeap()));
+    CpuAction* action = static_cast<CpuAction*>(actionHeapPop());
     XBT_CDEBUG(surf_kernel, "Something happened to action %p", action);
     if (TRACE_is_enabled()) {
       Cpu *cpu = static_cast<Cpu*>(lmm_constraint_id(lmm_get_cnst_from_var(getMaxminSystem(), action->getVariable(), 0)));
index 8818c21..42d080f 100644 (file)
@@ -359,8 +359,8 @@ double CpuTiModel::nextOccuringEvent(double now)
   }
 
 /* get the min next event if heap not empty */
-  if (xbt_heap_size(getActionHeap()) > 0)
-    min_action_duration = xbt_heap_maxkey(getActionHeap()) - now;
+  if (not actionHeapIsEmpty())
+    min_action_duration = actionHeapTopDate() - now;
 
   XBT_DEBUG("Share resources, min next event date: %f", min_action_duration);
 
@@ -369,8 +369,8 @@ double CpuTiModel::nextOccuringEvent(double now)
 
 void CpuTiModel::updateActionsState(double now, double /*delta*/)
 {
-  while ((xbt_heap_size(getActionHeap()) > 0) && (xbt_heap_maxkey(getActionHeap()) <= now)) {
-    CpuTiAction* action = static_cast<CpuTiAction*>(xbt_heap_pop(getActionHeap()));
+  while (not actionHeapIsEmpty() && actionHeapTopDate() <= now) {
+    CpuTiAction* action = static_cast<CpuTiAction*>(actionHeapPop());
     XBT_DEBUG("Action %p: finish", action);
     action->finish(Action::State::done);
     /* set the remains to 0 due to precision problems when updating the remaining amount */
index 35db28a..e1896d3 100644 (file)
@@ -171,10 +171,9 @@ LinkImpl* NetworkCm02Model::createLink(const std::string& name, double bandwidth
 
 void NetworkCm02Model::updateActionsStateLazy(double now, double /*delta*/)
 {
-  while ((xbt_heap_size(getActionHeap()) > 0) &&
-         (double_equals(xbt_heap_maxkey(getActionHeap()), now, sg_surf_precision))) {
+  while (not actionHeapIsEmpty() && double_equals(actionHeapTopDate(), now, sg_surf_precision)) {
 
-    NetworkCm02Action* action = static_cast<NetworkCm02Action*>(xbt_heap_pop(getActionHeap()));
+    NetworkCm02Action* action = static_cast<NetworkCm02Action*>(actionHeapPop());
     XBT_DEBUG("Something happened to action %p", action);
     if (TRACE_is_enabled()) {
       int n = lmm_get_number_of_cnst_from_var(maxminSystem_, action->getVariable());
index 13ee74b..01318ca 100644 (file)
@@ -444,8 +444,8 @@ double Model::nextOccuringEventLazy(double now)
   }
 
   //hereafter must have already the min value for this resource model
-  if (xbt_heap_size(actionHeap_) > 0) {
-    double min = xbt_heap_maxkey(actionHeap_) - now;
+  if (not actionHeapIsEmpty()) {
+    double min = actionHeapTopDate() - now;
     XBT_DEBUG("minimum with the HEAP %f", min);
     return min;
   } else {
index 1ace36d..719a3c4 100644 (file)
@@ -302,6 +302,10 @@ public:
   /** @brief Get Action heap */
   xbt_heap_t getActionHeap() {return actionHeap_;}
 
+  double actionHeapTopDate() const { return xbt_heap_maxkey(actionHeap_); }
+  Action* actionHeapPop() { return static_cast<Action*>(xbt_heap_pop(actionHeap_)); }
+  bool actionHeapIsEmpty() const { return xbt_heap_size(actionHeap_) == 0; }
+
   /**
    * @brief Share the resources between the actions
    *