@@ -124,8 +124,6 @@ bool Plan::AddSubTarget(const Node* node, const Node* dependent, string* err,
124
124
if (node->dirty () && want == kWantNothing ) {
125
125
want = kWantToStart ;
126
126
EdgeWanted (edge);
127
- if (!dyndep_walk && edge->AllInputsReady ())
128
- ScheduleWork (want_ins.first );
129
127
}
130
128
131
129
if (dyndep_walk)
@@ -514,14 +512,27 @@ int64_t AssignEdgeRuntime(BuildLog* build_log,
514
512
return total_time;
515
513
}
516
514
515
+ int64_t AssignDefaultEdgeRuntime (std::map<Edge*, Plan::Want> &want) {
516
+ int64_t total_time = 0 ;
517
+
518
+ for (std::map<Edge*, Plan::Want>::const_iterator it = want.begin (),
519
+ end = want.end ();
520
+ it != end; ++it) {
521
+ Edge* edge = it->first ;
522
+ if (edge->is_phony ()) {
523
+ continue ;
524
+ }
525
+
526
+ edge->set_run_time_ms (1 );
527
+ ++total_time;
528
+ }
529
+ return total_time;
530
+ }
531
+
517
532
} // namespace
518
533
519
534
void Plan::ComputeCriticalTime (BuildLog* build_log) {
520
- // testcases have no build_log
521
- if (!build_log)
522
- return ;
523
-
524
- METRIC_RECORD (" ComputePriorityList" );
535
+ METRIC_RECORD (" ComputeCriticalTime" );
525
536
// Remove duplicate targets
526
537
{
527
538
std::set<const Node*> seen;
@@ -533,7 +544,10 @@ void Plan::ComputeCriticalTime(BuildLog* build_log) {
533
544
// total time if building all edges in serial. This value is big
534
545
// enough to ensure higher priority target's initial critical time
535
546
// is always bigger than lower ones
536
- int64_t total_time = AssignEdgeRuntime (build_log, want_);
547
+ const int64_t total_time = build_log ?
548
+ AssignEdgeRuntime (build_log, want_) :
549
+ AssignDefaultEdgeRuntime (want_); // Plan tests have no build_log
550
+
537
551
538
552
// Use backflow algorithm to compute critical times for all nodes, starting
539
553
// from the destination nodes.
@@ -582,6 +596,42 @@ void Plan::ComputeCriticalTime(BuildLog* build_log) {
582
596
}
583
597
}
584
598
599
+ void Plan::ScheduleInitialEdges () {
600
+ // Add ready edges to queue.
601
+ assert (ready_.empty ());
602
+ std::set<Pool*> pools;
603
+
604
+ for (std::map<Edge*, Plan::Want>::iterator it = want_.begin (),
605
+ end = want_.end (); it != end; ++it) {
606
+ Edge* edge = it->first ;
607
+ Plan::Want want = it->second ;
608
+ if (!(want == kWantToStart && edge->AllInputsReady ())) {
609
+ continue ;
610
+ }
611
+
612
+ Pool* pool = edge->pool ();
613
+ if (pool->ShouldDelayEdge ()) {
614
+ pool->DelayEdge (edge);
615
+ pools.insert (pool);
616
+ } else {
617
+ ScheduleWork (it);
618
+ }
619
+ }
620
+
621
+ // Call RetrieveReadyEdges only once at the end so higher priority
622
+ // edges are retrieved first, not the ones that happen to be first
623
+ // in the want_ map.
624
+ for (std::set<Pool*>::iterator it=pools.begin (),
625
+ end = pools.end (); it != end; ++it) {
626
+ (*it)->RetrieveReadyEdges (&ready_);
627
+ }
628
+ }
629
+
630
+ void Plan::PrepareQueue (BuildLog* build_log) {
631
+ ComputeCriticalTime (build_log);
632
+ ScheduleInitialEdges ();
633
+ }
634
+
585
635
void Plan::Dump () const {
586
636
printf (" pending: %d\n " , (int )want_.size ());
587
637
for (map<Edge*, Want>::const_iterator e = want_.begin (); e != want_.end (); ++e) {
@@ -743,8 +793,7 @@ bool Builder::AlreadyUpToDate() const {
743
793
744
794
bool Builder::Build (string* err) {
745
795
assert (!AlreadyUpToDate ());
746
-
747
- plan_.ComputeCriticalTime (scan_.build_log ());
796
+ plan_.PrepareQueue (scan_.build_log ());
748
797
749
798
status_->PlanHasTotalEdges (plan_.command_edge_count ());
750
799
int pending_commands = 0 ;
0 commit comments