1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2025-05-05 17:04:11 +00:00

Improve queue management

This commit is contained in:
Carles Fernandez 2016-10-03 13:43:20 +02:00
parent a9c77b22ff
commit 047ced2b20
2 changed files with 13 additions and 10 deletions

View File

@ -34,7 +34,9 @@
#include "control_thread.h" #include "control_thread.h"
#include <unistd.h> #include <unistd.h>
#include <cmath>
#include <iostream> #include <iostream>
#include <limits>
#include <map> #include <map>
#include <string> #include <string>
#include <sys/types.h> #include <sys/types.h>
@ -528,16 +530,18 @@ void ControlThread::sysv_queue_listener()
int msgrcv_size = sizeof(msg.ttff); int msgrcv_size = sizeof(msg.ttff);
int msqid; int msqid;
key_t key = 1102; key_t key = 1102;
// wait for the queue to be created
if((msqid = msgget(key, 0644 | IPC_CREAT )) == -1)
{
perror("msgget");
}
while(read_queue) while(read_queue)
{ {
while((msqid = msgget(key, 0644)) == -1){}
if (msgrcv(msqid, &msg, msgrcv_size, 1, 0) != -1) if (msgrcv(msqid, &msg, msgrcv_size, 1, 0) != -1)
{ {
ttff_msg = msg.ttff; ttff_msg = msg.ttff;
if(ttff_msg == 200) if( (std::abs(ttff_msg - (-200.0)) < 10 * std::numeric_limits<double>::epsilon()) )
{ {
std::cout << "Quit order received, stopping GNSS-SDR !!" << std::endl; std::cout << "Quit order received, stopping GNSS-SDR !!" << std::endl;
std::unique_ptr<ControlMessageFactory> cmf(new ControlMessageFactory()); std::unique_ptr<ControlMessageFactory> cmf(new ControlMessageFactory());
@ -548,7 +552,9 @@ void ControlThread::sysv_queue_listener()
read_queue = false; read_queue = false;
} }
} }
usleep(1000000);
} }
msgctl(msqid, IPC_RMID, NULL);
} }

View File

@ -248,7 +248,7 @@ void receive_msg()
ttff_msgbuf msg; ttff_msgbuf msg;
ttff_msgbuf msg_stop; ttff_msgbuf msg_stop;
msg_stop.mtype = 1; msg_stop.mtype = 1;
msg_stop.ttff = 200; msg_stop.ttff = -200.0;
double ttff_msg = 0.0; double ttff_msg = 0.0;
int msgrcv_size = sizeof(msg.ttff); int msgrcv_size = sizeof(msg.ttff);
int msqid; int msqid;
@ -266,7 +266,8 @@ void receive_msg()
TTFF_v.push_back(ttff_msg / (1000.0 / decimation_factor) ); TTFF_v.push_back(ttff_msg / (1000.0 / decimation_factor) );
LOG(INFO) << "Valid Time-To-First-Fix: " << ttff_msg / (1000.0 / decimation_factor ) << "[s]"; LOG(INFO) << "Valid Time-To-First-Fix: " << ttff_msg / (1000.0 / decimation_factor ) << "[s]";
// Stop the receiver // Stop the receiver
while(((msqid_stop = msgget(key_stop, 0644 | IPC_CREAT))) == -1){} //while(((msqid_stop = msgget(key_stop, 0644 | IPC_CREAT))) == -1){}
while(((msqid_stop = msgget(key_stop, 0644))) == -1){}
double msgsend_size = sizeof(msg_stop.ttff); double msgsend_size = sizeof(msg_stop.ttff);
msgsnd(msqid_stop, &msg_stop, msgsend_size, IPC_NOWAIT); msgsnd(msqid_stop, &msg_stop, msgsend_size, IPC_NOWAIT);
} }
@ -275,10 +276,6 @@ void receive_msg()
{ {
receive_msg(); receive_msg();
} }
else
{
if(msqid_stop != -1) msgctl(msqid_stop, IPC_RMID, NULL);
}
} }
return; return;
} }