Export source code by gbs use threads. Create a number of threads as host's CPU
authorjun.wang <junbill.wang@samsung.com>
Tue, 5 Jul 2016 08:40:27 +0000 (16:40 +0800)
committerSoonKyu Park <sk7.park@samsung.com>
Mon, 26 Dec 2016 12:02:10 +0000 (21:02 +0900)
Path form review.tizen.org ,commitID: ece9d874772d291b3091f051adc346b1133cbb3e

Change-Id: I38f8d7e9f9639a47c573717136804be034b45043

depanneur

index e4abc82..1797d1d 100755 (executable)
--- a/depanneur
+++ b/depanneur
@@ -19,6 +19,7 @@ BEGIN {
 use YAML qw(LoadFile);
 use threads;
 use threads::shared;
+use Thread::Queue;
 use File::Find ();
 use Term::ANSIColor qw(:constants);
 use File::Path;
@@ -753,6 +754,7 @@ sub prepare_git {
     my $config = shift;
     my $base = shift;
     my $spec = shift;
+    my $packs_queue = shift;
     my $spec_file = basename($spec);
 
     if ($includeall == 0 || $spec_commit ne "") {
@@ -820,7 +822,7 @@ sub prepare_git {
     # check whether it's really successful to export
     if ( -e "$pkg_path/$cache_key/$spec_file" ){
         # prepare to build the packages had been exported
-        push(@packs, {
+       $packs_queue->enqueue({
             filename => "$pkg_path/$cache_key/$spec_file",
             project_base_path => $base,
         });
@@ -2091,9 +2093,34 @@ if ($style eq 'git') {
     }
     if ($incremental == 0) {
         info("prepare sources...");
-        foreach my $pack (@pre_packs) {
-            prepare_git($config, $pack->{"project_base_path"}, $pack->{"filename"});
-        }
+
+       my $packs_queue = Thread::Queue->new();
+       my $data_queue = Thread::Queue->new();
+       foreach my $pack (@pre_packs) {
+               $data_queue->enqueue($pack);
+       }
+
+       my $thread_num = int(sysconf(SC_NPROCESSORS_ONLN));
+       for (0..$thread_num) {
+               $data_queue->enqueue(undef);
+               threads->create(sub {
+                       while (my $pack = $data_queue->dequeue()) {
+                               prepare_git($config, $pack->{"project_base_path"}, $pack->{"filename"}, $packs_queue);
+                       }
+               });
+       }
+       foreach (threads->list()) { $_->join(); }
+       # Check error
+       foreach (threads->list()) {
+               if (my $chk_err = $_->error()){
+                       warning("export thread error: $chk_err\n");
+               }
+       }
+       $packs_queue->enqueue(undef);
+       while (my $pack = $packs_queue->dequeue()) {
+               push @packs, $pack;
+       }
+
     } else {
         @packs = @pre_packs;
     }
@@ -2103,7 +2130,6 @@ if ($style eq 'git') {
         File::Find::find({wanted => \&obs_wanted}, $package_path );
     }
 }
-
 if ($clean_repos && -e "$localrepo/$dist/$arch") {
     info("cleaning up local repo: $rpm_repo_path ...");
     my_system("rm -rf $rpm_repo_path/*");