#---------------------------------------------------------------------
# check state of every thread in thread pool
-# and return a idle one to use
+# and mark it as idle if it has been finished
#---------------------------------------------------------------------
-sub find_idle {
- my $idle = -1;
- foreach my $w (sort keys %workers) {
+sub set_idle_of_all_finished_thread {
+ foreach my $w (sort { $a <=> $b } keys %workers) {
my $tid = $workers{$w}->{tid};
- my $state = $workers{$w}->{state};
# check the thread id, set it state idle
# if it has been finished
if (! defined(threads->object($tid))) {
set_idle($w);
- $idle = $w;
- last;
}
}
+}
+
+#---------------------------------------------------------------------
+# check state of every thread in thread pool
+# and return a idle one to use
+#---------------------------------------------------------------------
+sub find_idle {
+ my $idle = -1;
+ set_idle_of_all_finished_thread();
# find a idle one to return pool id
- foreach my $w (sort keys %workers) {
+ foreach my $w (sort { $a <=> $b } keys %workers) {
if ( $workers{$w}->{state} eq 'idle' ) {
$idle = $w;
last;
return $idle;
}
+#---------------------------------------------------------------------
+# check state of every thread in thread pool
+# and return the number of idle workers
+#---------------------------------------------------------------------
+sub no_of_idle_thread {
+ set_idle_of_all_finished_thread();
+ my @idle_workers = ();
+ foreach my $w (sort { $a <=> $b } keys %workers) {
+ if ( $workers{$w}->{state} eq 'idle' ) {
+ push (@idle_workers, $w);
+ }
+ }
+ return scalar @idle_workers;
+}
+
#---------------------------------------------------------------------
# set state of its thread in pool busy
#---------------------------------------------------------------------
my @order = ();
my @order_clean = ();
+ set_idle_of_all_finished_thread();
+ my $no_of_idles = no_of_idle_thread();
+
{
# update glocal vars %repo and %pkgdeps etc.
# so lock it
}
if ($add == 1 ) {
push(@order, $name);
- last;
+ if ($no_of_idles <= scalar @order) {
+ last;
+ }
}
} else {
- push(@order_clean, $name);
- }
+ push(@order_clean, $name);
+ }
+ }
+ #remove unuseful package name from build_order
+ foreach my $u_name (@order_clean) {
+ @build_order = grep { $_ ne $u_name} @build_order;
}
- #remove unuseful package name from build_order
- foreach my $u_name (@order_clean) {
- @build_order = grep { $_ ne $u_name} @build_order;
- }
# No candidate packges and all thread works are idle, and pkgdeps
# is updated, in this case, set packages in %tmp_expansion_errors