summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobert Iannucci <robbie@rail.com>2012-10-04 00:25:23 (GMT)
committerRobert A Iannucci Jr <iannucci@chromium.org>2012-11-09 04:25:39 (GMT)
commit307f0bbd13d881cc2883c3e5f7f385b8f7914480 (patch)
tree2950aeabc8412b3662d4abcf4387bffae15eafa2
parentaca4ec54656057e58ca7a9ae5de7f94c869b2ccb (diff)
downloadNinja-307f0bbd13d881cc2883c3e5f7f385b8f7914480.zip
Ninja-307f0bbd13d881cc2883c3e5f7f385b8f7914480.tar.gz
Ninja-307f0bbd13d881cc2883c3e5f7f385b8f7914480.tar.bz2
and some basic implementation
-rw-r--r--src/build.cc20
-rw-r--r--src/graph.h2
-rw-r--r--src/state.cc27
-rw-r--r--src/state.h12
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<Edge*>* 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<Edge*>* ready_queue);
+ void RetrieveReadyEdges(set<Edge*>* ready_queue);
private:
+ int UnitsWaiting() { return delayed_.size(); }
+
string name_;
int current_use_;