Skip to content

Commit

Permalink
no need to pass threads number, just iterating on the array is enough
Browse files Browse the repository at this point in the history
  • Loading branch information
guillomovitch committed Jul 2, 2011
1 parent 4199650 commit 571e7e2
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions lib/FusionInventory/Agent/Task/NetDiscovery.pm
Expand Up @@ -107,7 +107,6 @@ sub run {

my $exit : shared = 0;

my $loop_nbthreads : shared;
my $sendbylwp : shared;

# convert given IP ranges into a flat list of IP addresses
Expand Down Expand Up @@ -159,15 +158,12 @@ sub run {
$self,
\@addresses,
$exit,
$loop_nbthreads,
\@threads
)->detach();

while (@addresses) {
@addresses_block = splice @addresses, 0, $block_size;

$loop_nbthreads = $params->{THREADS_DISCOVERY};

$exit = 2;

# Send infos to server :
Expand Down Expand Up @@ -383,7 +379,7 @@ sub _handleIPRange {
}

sub _manageThreads {
my ($self, $addresses, $exit, $loop_nbthreads, $threads) = @_;
my ($self, $addresses, $exit, $threads) = @_;

my $count;
my $i;
Expand All @@ -394,20 +390,20 @@ sub _manageThreads {
## Kill threads who do nothing partial ##

## Start + end working threads (do a function) ##
for($i = 0 ; $i < $loop_nbthreads ; $i++) {
$threads->[$i]->{action} = STOP;
foreach my $thread (@$threads) {
$thread->{action} = STOP;
}
## Function state of working threads (if they are stopped) ##
$count = 0;
$loopthread = 0;

while ($loopthread != 1) {
for($i = 0 ; $i < $loop_nbthreads ; $i++) {
if ($threads->[$i]->{state} == STOP) {
$count++;
}
foreach my $thread (@$threads) {
if ($thread->{state} == STOP) {
$count++;
}
}
if ($count eq $loop_nbthreads) {
if ($count eq @$threads) {
$loopthread = 1;
} else {
$count = 0;
Expand All @@ -419,8 +415,8 @@ sub _manageThreads {

} elsif ((@$addresses >= 0) && ($exit == 2)) {
## Start + pause working Threads (do a function) ##
for($i = 0 ; $i < $loop_nbthreads ; $i++) {
$threads->[$i]->{action} = RUN;
foreach my $thread (@$threads) {
$thread->{action} = RUN;
}
sleep 1;

Expand All @@ -429,12 +425,12 @@ sub _manageThreads {
$loopthread = 0;

while ($loopthread != 1) {
for($i = 0 ; $i < $loop_nbthreads ; $i++) {
if ($threads->[$i]->{state} == PAUSE) {
$count++;
}
foreach my $thread (@$threads) {
if ($thread->{state} == PAUSE) {
$count++;
}
}
if ($count eq $loop_nbthreads) {
if ($count eq @$threads) {
$loopthread = 1;
} else {
$count = 0;
Expand Down

0 comments on commit 571e7e2

Please sign in to comment.