Skip to content

Commit

Permalink
no need to use two different lists, the second only containing indice…
Browse files Browse the repository at this point in the history
…s for the first one, just pop items from the list directly
  • Loading branch information
guillomovitch committed Jun 21, 2011
1 parent 6e5576f commit ab1c8b6
Showing 1 changed file with 17 additions and 23 deletions.
40 changes: 17 additions & 23 deletions lib/FusionInventory/Agent/Task/NetDiscovery.pm
Expand Up @@ -95,7 +95,6 @@ sub run {

# manage discovery
my $iplist = &share([]);
my $iplist2 = &share([]);
my $maxIdx : shared = 0;
my $sendstart = 0;
my $startIP = q{}; # Empty string
Expand Down Expand Up @@ -140,7 +139,6 @@ sub run {
$nbip = 0;

if ($threads_run == 0) {
$iplist2 = &share([]);
$iplist = &share([]);
}

Expand All @@ -151,9 +149,10 @@ sub run {
if ($threads_run == 0) {
$iplist->[$countnb] = &share([]);
}
$iplist->[$countnb]->{IP} = $range->{IPSTART};
$iplist->[$countnb]->{ENTITY} = $range->{ENTITY};
$iplist2->[$countnb] = $countnb;
$iplist->[$countnb] = {
IP => $range->{IPSTART},
ENTITY => $range->{ENTITY}
};
$countnb++;
$nbip++;
} else {
Expand All @@ -162,9 +161,10 @@ sub run {
if ($threads_run == 0) {
$iplist->[$countnb] = &share({});
}
$iplist->[$countnb]->{IP} = $ip->ip();
$iplist->[$countnb]->{ENTITY} = $range->{ENTITY};
$iplist2->[$countnb] = $countnb;
$iplist->[$countnb] = {
IP => $ip->ip(),
ENTITY => $range->{ENTITY}
};
$countnb++;
$nbip++;
if ($nbip eq $limitip) {
Expand Down Expand Up @@ -208,7 +208,6 @@ sub run {
\@ThreadAction,
\@ThreadState,
$iplist,
$iplist2,
$nmap_parameters,
$dico,
$maxIdx,
Expand Down Expand Up @@ -366,11 +365,10 @@ sub _getDictionnary {
}

sub _handleIPRange {
my ($self, $p, $t, $credentials, $ThreadAction, $ThreadState, $iplist2, $iplist, $nmap_parameters, $dico, $maxIdx, $pid) = @_;
my ($self, $p, $t, $credentials, $ThreadAction, $ThreadState, $iplist, $nmap_parameters, $dico, $maxIdx, $pid) = @_;
my $loopthread = 0;
my $loopbigthread = 0;
my $count = 0;
my $device_id;
my $data;

$self->{logger}->debug("Core $p - Thread $t created");
Expand All @@ -391,32 +389,28 @@ sub _handleIPRange {
##### RUN ACTION #####
$loopthread = 0;
while ($loopthread != 1) {
$device_id = q{}; # Empty string
my $item;
{
lock $iplist2;
if (@{$iplist2}) {
$device_id = pop @{$iplist2};
} else {
$loopthread = 1;
}
lock $iplist;
$item = pop @{$iplist};
}
if ($loopthread != 1) {
if ($item) {
my $datadevice = $self->_probeAddress(
ip => $iplist->[$device_id]->{IP},
entity => $iplist->[$device_id]->{ENTITY},
ip => $item->{IP},
entity => $item->{ENTITY},
credentials => $credentials,
nmap_parameters => $nmap_parameters,
dico => $dico
);
undef $iplist->[$device_id]->{IP};
undef $iplist->[$device_id]->{ENTITY};

if (keys %{$datadevice}) {
$data->{DEVICE}->[$count] = $datadevice;
$data->{MODULEVERSION} = $VERSION;
$data->{PROCESSNUMBER} = $pid;
$count++;
}
} else {
$loopthread = 1;
}
if (($count == 4) || (($loopthread == 1) && ($count > 0))) {
$maxIdx++;
Expand Down

0 comments on commit ab1c8b6

Please sign in to comment.