2008-04-22 Ramon Novoa <rnovoa@artica.es>

* bin/pandora_plugin, bin/pandora_prediction,
          bin/pandora_network: Consumer threads now check for data
          availability after lock() to avoid race conditions.




git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@814 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
ramonn 2008-04-22 14:35:19 +00:00
parent ea0fdae0f9
commit 11480364f7
4 changed files with 92 additions and 83 deletions

View File

@ -1,3 +1,9 @@
2008-04-22 Ramon Novoa <rnovoa@artica.es>
* bin/pandora_plugin, bin/pandora_prediction,
bin/pandora_network: Consumer threads now check for data
availability after lock() to avoid race conditions.
2008-04-22 Ramon Novoa <rnovoa@artica.es>
* bin/pandora_server: The data server now uses the producer/consumer

View File

@ -144,7 +144,7 @@ sub pandora_network_consumer ($$) {
my $dbh = DBI->connect("DBI:mysql:$pa_config->{'dbname'}:$pa_config->{'dbhost'}:3306", $pa_config->{'dbuser'}, $pa_config->{'dbpass'}, { RaiseError => 1, AutoCommit => 1 });
my $counter =0;
while (1) {
LOOP: while (1) {
if ($counter > 10) {
sleep (1);
$counter = 0;
@ -152,9 +152,13 @@ sub pandora_network_consumer ($$) {
# Take the first element on the shared queue
# Insert this element on the current task hash
if (scalar(@pending_task) > 0){
{
lock $queue_lock;
if (scalar(@pending_task) == 0){
$counter++;
next LOOP;
}
$data_id_agent_module = shift(@pending_task);
delete($pending_task_hash{$data_id_agent_module});
$current_task_hash{$data_id_agent_module}=1;
@ -177,9 +181,6 @@ sub pandora_network_consumer ($$) {
delete($current_task_hash{$data_id_agent_module});
}
$counter = 0;
} else {
$counter ++;
}
}
}

View File

@ -132,7 +132,7 @@ sub pandora_plugin_consumer ($$) {
my $dbh = DBI->connect("DBI:mysql:$pa_config->{'dbname'}:$pa_config->{'dbhost'}:3306", $pa_config->{'dbuser'}, $pa_config->{'dbpass'}, { RaiseError => 1, AutoCommit => 1 });
my $counter =0;
while (1) {
LOOP: while (1) {
if ($counter > 10) {
sleep (1);
$counter = 0;
@ -140,9 +140,13 @@ sub pandora_plugin_consumer ($$) {
# Take the first element on the shared queue
# Insert this element on the current task hash
if (scalar(@pending_task) > 0){
{
lock $queue_lock;
if (scalar(@pending_task) == 0){
$counter++;
next LOOP;
}
$data_id_agent_module = shift(@pending_task);
#print "[CLIENT] Pop out of queue module (pending queue) $data_id_agent_module \n";
delete($pending_task_hash{$data_id_agent_module});
@ -169,9 +173,6 @@ print "[CLIENT] Executing module $data_id_agent_module \n";
delete($current_task_hash{$data_id_agent_module});
}
$counter = 0;
} else {
$counter ++;
}
}
}

View File

@ -128,7 +128,7 @@ sub pandora_prediction_consumer ($$) {
my $dbh = DBI->connect("DBI:mysql:$pa_config->{'dbname'}:$pa_config->{'dbhost'}:3306", $pa_config->{'dbuser'}, $pa_config->{'dbpass'}, { RaiseError => 1, AutoCommit => 1 });
my $counter =0;
while (1) {
LOOP: while (1) {
if ($counter > 10) {
sleep (1);
$counter = 0;
@ -136,9 +136,13 @@ sub pandora_prediction_consumer ($$) {
# Take the first element on the shared queue
# Insert this element on the current task hash
if (scalar(@pending_task) > 0){
{
lock $queue_lock;
if (scalar(@pending_task) == 0){
$counter++;
next LOOP;
}
$data_id_agent_module = shift(@pending_task);
delete($pending_task_hash{$data_id_agent_module});
$current_task_hash{$data_id_agent_module}=1;
@ -162,9 +166,6 @@ sub pandora_prediction_consumer ($$) {
delete($current_task_hash{$data_id_agent_module});
}
$counter = 0;
} else {
$counter ++;
}
}
}