]> git.tdb.fi Git - builder.git/commitdiff
Improve task management to use blocking wait if possible
authorMikko Rasa <tdb@tdb.fi>
Thu, 19 Jul 2012 10:41:40 +0000 (13:41 +0300)
committerMikko Rasa <tdb@tdb.fi>
Thu, 19 Jul 2012 10:41:40 +0000 (13:41 +0300)
source/builder.cpp

index df7edabbd8e0bae1f28782f3f0bc3a4ffe19e8a2..7b0f0187f762cf03defc63645cc285f9db647934 100644 (file)
@@ -457,10 +457,11 @@ int Builder::do_build()
 
        bool fail = false;
        bool finish = false;
+       bool starved = false;
 
        while(!finish)
        {
-               if(tasks.size()<jobs && !fail)
+               if(tasks.size()<jobs && !fail && !starved)
                {
                        Target *tgt = cmdline->get_buildable_target();
                        if(tgt)
@@ -488,13 +489,20 @@ int Builder::do_build()
                        }
                        else if(tasks.empty())
                                finish = true;
+                       else
+                               starved = true;
                }
                else
                        Time::sleep(10*Time::msec);
 
                for(unsigned i=0; i<tasks.size();)
                {
-                       Task::Status status = tasks[i]->check();
+                       Task::Status status;
+                       if(jobs==1 || (tasks.size()==1 && starved))
+                               status = tasks[i]->wait();
+                       else
+                               status = tasks[i]->check();
+
                        if(status!=Task::RUNNING)
                        {
                                ++count;
@@ -505,6 +513,7 @@ int Builder::do_build()
                                        fail = true;
                                if(tasks.empty() && fail)
                                        finish = true;
+                               starved = false;
                        }
                        else
                                ++i;