From 307f0bbd13d881cc2883c3e5f7f385b8f7914480 Mon Sep 17 00:00:00 2001 From: Robert Iannucci Date: Wed, 3 Oct 2012 17:25:23 -0700 Subject: and some basic implementation --- src/build.cc | 20 ++++++++++---------- src/graph.h | 2 ++ src/state.cc | 27 +++++++++++++++++++++++++++ src/state.h | 12 +++++++----- 4 files changed, 46 insertions(+), 15 deletions(-) diff --git a/src/build.cc b/src/build.cc index 0710e51..2794c6c 100644 --- a/src/build.cc +++ b/src/build.cc @@ -409,19 +409,19 @@ Edge* Plan::FindWork() { } void Plan::ScheduleWork(Edge* edge) { - // TODO(iannucci): See if this should get delayed instead - // if edge has pool - // create pool if DNE - // pool.InsertEdge(edge) - // ready_.insert(pool.GetAvailableEdges()) - // else - ready_.insert(edge); + Pool& pool = edge->pool(); + if (pool.ShouldDelayEdge(*edge)) { + pool.DelayEdge(edge); + pool.RetrieveReadyEdges(&ready_); + } else { + pool.EdgeScheduled(*edge); + ready_.insert(edge); + } } void Plan::ResumeDelayedJobs(Edge* edge) { - // if edge has pool - // pool.ReturnUnits(edge) - // ready_.insert(pool.GetAvailableEdges()) + edge->pool().EdgeFinished(*edge); + edge->pool().RetrieveReadyEdges(&ready_); } void Plan::EdgeFinished(Edge* edge) { diff --git a/src/graph.h b/src/graph.h index a35ab65..9e924f7 100644 --- a/src/graph.h +++ b/src/graph.h @@ -174,6 +174,8 @@ struct Edge { bool outputs_ready_; const Rule& rule() const { return *rule_; } + Pool& pool() const { return *pool_; } + int weight() const { return 1; } bool outputs_ready() const { return outputs_ready_; } // XXX There are three types of inputs. diff --git a/src/state.cc b/src/state.cc index e8e6dc3..b34b938 100644 --- a/src/state.cc +++ b/src/state.cc @@ -22,6 +22,33 @@ #include "metrics.h" #include "util.h" + +void Pool::EdgeScheduled(const Edge& edge) { + if (depth_ != 0) + current_use_ += edge.weight(); +} + +void Pool::EdgeFinished(const Edge& edge) { + if (depth_ != 0) + current_use_ -= edge.weight(); +} + +void Pool::DelayEdge(Edge* edge) { + assert(depth_ != 0); + delayed_.push(edge); +} + +void Pool::RetrieveReadyEdges(set* ready_queue) { + while(!delayed_.empty()) { + Edge* edge = delayed_.front(); + if(current_use_ + edge->weight() > depth_) + break; + delayed_.pop(); + ready_queue->insert(edge); + EdgeScheduled(*edge); + } +} + Pool State::kDefaultPool("", 0); const Rule State::kPhonyRule("phony"); diff --git a/src/state.h b/src/state.h index 3e569cf..e3137c4 100644 --- a/src/state.h +++ b/src/state.h @@ -39,24 +39,26 @@ struct Pool { int depth() const { return depth_; } const string& name() const { return name_; } - /// true if the Pool would delay this edge - bool ShouldDelayEdge(Edge* edge); + /// true if the Pool might delay this edge + bool ShouldDelayEdge(const Edge& edge) const { return depth_ == 0; } /// informs this Pool that the given edge is committed to be run. /// Pool will count this edge as using resources from this pool. - void EdgeScheduled(Edge* edge); + void EdgeScheduled(const Edge& edge); /// informs this Pool that the given edge is no longer runnable, and should /// relinquish it's resources back to the pool - void EdgeFinished(Edge* edge); + void EdgeFinished(const Edge& edge); /// adds the given edge to this Pool to be delayed. void DelayEdge(Edge* edge); /// Pool will add zero or more edges to the ready_queue - void RetrieveReadyEdges(Edge* edge, set* ready_queue); + void RetrieveReadyEdges(set* ready_queue); private: + int UnitsWaiting() { return delayed_.size(); } + string name_; int current_use_; -- cgit v0.12