Improve queue management gnss-sdr and in TTFF tests.

Always destroy queues when exiting
This commit is contained in:
Carles Fernandez 2016-10-03 17:43:06 +02:00
parent 047ced2b20
commit 08f0a36075
6 changed files with 43 additions and 34 deletions

View File

@ -213,7 +213,9 @@ galileo_e1_pvt_cc::galileo_e1_pvt_cc(unsigned int nchannels, bool dump, std::str
galileo_e1_pvt_cc::~galileo_e1_pvt_cc()
{}
{
msgctl(sysv_msqid, IPC_RMID, NULL);
}

View File

@ -313,7 +313,9 @@ gps_l1_ca_pvt_cc::gps_l1_ca_pvt_cc(unsigned int nchannels,
gps_l1_ca_pvt_cc::~gps_l1_ca_pvt_cc()
{}
{
msgctl(sysv_msqid, IPC_RMID, NULL);
}
bool pseudoranges_pairCompare_min(const std::pair<int,Gnss_Synchro>& a, const std::pair<int,Gnss_Synchro>& b)

View File

@ -290,7 +290,9 @@ hybrid_pvt_cc::hybrid_pvt_cc(unsigned int nchannels, bool dump, std::string dump
hybrid_pvt_cc::~hybrid_pvt_cc()
{}
{
msgctl(sysv_msqid, IPC_RMID, NULL);
}

View File

@ -90,6 +90,7 @@ ControlThread::~ControlThread()
{
// save navigation data to files
// if (save_assistance_to_XML() == true) {}
if(msgiq != -1) msgctl(msqid, IPC_RMID, NULL);;
}
@ -431,6 +432,7 @@ void ControlThread::init()
supl_mns = 0;
supl_lac = 0;
supl_ci = 0;
msqid = -1;
}
@ -528,7 +530,7 @@ void ControlThread::sysv_queue_listener()
ttff_msgbuf msg;
double ttff_msg = 0.0;
int msgrcv_size = sizeof(msg.ttff);
int msqid;
key_t key = 1102;
if((msqid = msgget(key, 0644 | IPC_CREAT )) == -1)
@ -552,9 +554,7 @@ void ControlThread::sysv_queue_listener()
read_queue = false;
}
}
usleep(1000000);
}
msgctl(msqid, IPC_RMID, NULL);
}

View File

@ -143,7 +143,6 @@ private:
*/
void assist_GNSS();
void apply_action(unsigned int what);
std::shared_ptr<GNSSFlowgraph> flowgraph_;
std::shared_ptr<ConfigurationInterface> configuration_;
@ -160,6 +159,7 @@ private:
void keyboard_listener();
void sysv_queue_listener();
int msqid;
// default filename for assistance data
const std::string eph_default_xml_filename = "./gps_ephemeris.xml";

View File

@ -255,26 +255,30 @@ void receive_msg()
int msqid_stop = -1;
key_t key = 1101;
key_t key_stop = 1102;
// wait for the queue to be created
if((msqid = msgget(key, 0644)) == -1){}
bool leave = false;
if (msgrcv(msqid, &msg, msgrcv_size, 1, 0) != -1)
while(!leave)
{
ttff_msg = msg.ttff;
if( (ttff_msg != 0) && (ttff_msg != -1))
{
TTFF_v.push_back(ttff_msg / (1000.0 / decimation_factor) );
LOG(INFO) << "Valid Time-To-First-Fix: " << ttff_msg / (1000.0 / decimation_factor ) << "[s]";
// Stop the receiver
//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);
msgsnd(msqid_stop, &msg_stop, msgsend_size, IPC_NOWAIT);
}
// wait for the queue to be created
while((msqid = msgget(key, 0644)) == -1){}
if(ttff_msg != -1)
if (msgrcv(msqid, &msg, msgrcv_size, 1, 0) != -1)
{
receive_msg();
ttff_msg = msg.ttff;
if( (ttff_msg != 0) && (ttff_msg != -1))
{
TTFF_v.push_back(ttff_msg / (1000.0 / decimation_factor) );
LOG(INFO) << "Valid Time-To-First-Fix: " << ttff_msg / (1000.0 / decimation_factor ) << "[s]";
// Stop the receiver
while(((msqid_stop = msgget(key_stop, 0644))) == -1){}
double msgsend_size = sizeof(msg_stop.ttff);
msgsnd(msqid_stop, &msg_stop, msgsend_size, IPC_NOWAIT);
}
if(ttff_msg == -1)
{
leave = true;
}
}
}
return;
@ -586,17 +590,6 @@ int main(int argc, char **argv)
google::ParseCommandLineFlags(&argc, &argv, true);
google::InitGoogleLogging(argv[0]);
// Create SysV message queue to read TFFF measurements
key_t sysv_msg_key;
int sysv_msqid;
sysv_msg_key = 1101;
int msgflg = IPC_CREAT | 0666;
if ((sysv_msqid = msgget(sysv_msg_key, msgflg )) == -1)
{
std::cout<<"GNSS-SDR can not create message queues!" << std::endl;
throw new std::exception();
}
// Start queue thread
std::thread receive_msg_thread(receive_msg);
@ -611,6 +604,15 @@ int main(int argc, char **argv)
}
// Terminate the queue thread
key_t sysv_msg_key;
int sysv_msqid;
sysv_msg_key = 1101;
int msgflg = IPC_CREAT | 0666;
if ((sysv_msqid = msgget(sysv_msg_key, msgflg )) == -1)
{
std::cout<<"GNSS-SDR can not create message queues!" << std::endl;
throw new std::exception();
}
ttff_msgbuf msg;
msg.mtype = 1;
msg.ttff = -1;
@ -619,6 +621,7 @@ int main(int argc, char **argv)
msgsnd(sysv_msqid, &msg, msgsend_size, IPC_NOWAIT);
receive_msg_thread.join();
msgctl(sysv_msqid, IPC_RMID, NULL);
google::ShutDownCommandLineFlags();
return res;
}