diff --git a/src/CraneCtld/TaskScheduler.cpp b/src/CraneCtld/TaskScheduler.cpp index 6ee30e379..38dedfc1d 100644 --- a/src/CraneCtld/TaskScheduler.cpp +++ b/src/CraneCtld/TaskScheduler.cpp @@ -2128,13 +2128,12 @@ bool MinLoadFirst::CalculateRunningNodesAndStartTime_( while (!pq.empty() && pq.top()->it->first == time) { auto tracker = pq.top(); pq.pop(); - if (tracker->satisfied()) { + if (tracker->satisfied_flag) { satisfied_trackers.try_push_back(tracker, time); - if (tracker->genNextUnsatisfied()) pq.emplace(tracker); } else { satisfied_trackers.try_erase(tracker); - if (tracker->genNextSatisfied()) pq.emplace(tracker); } + if (tracker->genNext()) pq.emplace(tracker); } if (pq.empty() || satisfied_trackers.kth_time() + task->time_limit <= pq.top()->it->first) { diff --git a/src/CraneCtld/TaskScheduler.h b/src/CraneCtld/TaskScheduler.h index 305c6cbdb..156e1d3a3 100644 --- a/src/CraneCtld/TaskScheduler.h +++ b/src/CraneCtld/TaskScheduler.h @@ -162,6 +162,7 @@ class MinLoadFirst : public INodeSelectionAlgo { const TimeAvailResMap::const_iterator end; const ResourceInNode* task_res; void* tracker_list_elem; + bool satisfied_flag; TimeAvailResTracker(const CranedId& craned_id, const TimeAvailResMap::const_iterator& begin, @@ -171,10 +172,17 @@ class MinLoadFirst : public INodeSelectionAlgo { it(begin), end(end), task_res(task_res), - tracker_list_elem(nullptr) {} + tracker_list_elem(nullptr) { + satisfied_flag = satisfied(); + } bool satisfied() const { return *task_res <= it->second; } + bool genNext() { + satisfied_flag = !satisfied_flag; // target state + return satisfied_flag ? genNextSatisfied() : genNextUnsatisfied(); + } + bool genNextUnsatisfied() { while (++it != end && satisfied()); return it != end;