1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-12-15 04:30:33 +00:00

Avoid multithreading collision

This commit is contained in:
Antonio Ramos 2018-01-08 10:57:01 +01:00
parent cfc0a4a498
commit 74a1f76282
4 changed files with 90 additions and 44 deletions

View File

@ -197,7 +197,13 @@ void Channel::set_signal(const Gnss_Signal& gnss_signal)
void Channel::start_acquisition() void Channel::start_acquisition()
{ {
channel_fsm_.Event_start_acquisition(); bool result = false;
result = channel_fsm_.Event_start_acquisition();
if(!result)
{
LOG(WARNING) << "Invalid channel event";
return;
}
DLOG(INFO) << "Channel start_acquisition()"; DLOG(INFO) << "Channel start_acquisition()";
} }

View File

@ -53,53 +53,88 @@ ChannelFsm::ChannelFsm(std::shared_ptr<AcquisitionInterface> acquisition) :
} }
bool ChannelFsm::Event_start_acquisition()
void ChannelFsm::Event_start_acquisition()
{ {
mx.lock(); std::lock_guard<std::mutex> lk(mx);
d_state = 1; if((d_state == 1) || (d_state == 2))
start_acquisition(); {
DLOG(INFO) << "CH = " << channel_ << ". Ev start acquisition"; return false;
mx.unlock(); }
else
{
d_state = 1;
start_acquisition();
DLOG(INFO) << "CH = " << channel_ << ". Ev start acquisition";
return true;
}
} }
void ChannelFsm::Event_valid_acquisition() bool ChannelFsm::Event_valid_acquisition()
{ {
mx.lock(); std::lock_guard<std::mutex> lk(mx);
d_state = 2; if(d_state != 1)
start_tracking(); {
DLOG(INFO) << "CH = " << channel_ << ". Ev valid acquisition"; return false;
mx.unlock(); }
else
{
d_state = 2;
start_tracking();
DLOG(INFO) << "CH = " << channel_ << ". Ev valid acquisition";
return true;
}
} }
void ChannelFsm::Event_failed_acquisition_repeat() bool ChannelFsm::Event_failed_acquisition_repeat()
{ {
mx.lock(); std::lock_guard<std::mutex> lk(mx);
d_state = 1; if(d_state != 1)
start_acquisition(); {
DLOG(INFO) << "CH = " << channel_ << ". Ev failed acquisition repeat"; return false;
mx.unlock(); }
} else
{
void ChannelFsm::Event_failed_acquisition_no_repeat() d_state = 1;
{ start_acquisition();
mx.lock(); DLOG(INFO) << "CH = " << channel_ << ". Ev failed acquisition repeat";
d_state = 3; return true;
request_satellite(); }
DLOG(INFO) << "CH = " << channel_ << ". Ev failed acquisition no repeat";
mx.unlock();
} }
void ChannelFsm::Event_failed_tracking_standby() bool ChannelFsm::Event_failed_acquisition_no_repeat()
{ {
mx.lock(); std::lock_guard<std::mutex> lk(mx);
d_state = 0; if(d_state != 1)
notify_stop_tracking(); {
DLOG(INFO) << "CH = " << channel_ << ". Ev failed tracking standby"; return false;
mx.unlock(); }
else
{
d_state = 3;
request_satellite();
DLOG(INFO) << "CH = " << channel_ << ". Ev failed acquisition no repeat";
return true;
}
}
bool ChannelFsm::Event_failed_tracking_standby()
{
std::lock_guard<std::mutex> lk(mx);
if(d_state != 2)
{
return false;
}
else
{
d_state = 0;
notify_stop_tracking();
DLOG(INFO) << "CH = " << channel_ << ". Ev failed tracking standby";
return true;
}
} }
void ChannelFsm::set_acquisition(std::shared_ptr<AcquisitionInterface> acquisition) void ChannelFsm::set_acquisition(std::shared_ptr<AcquisitionInterface> acquisition)

View File

@ -54,11 +54,11 @@ public:
void set_channel(unsigned int channel); void set_channel(unsigned int channel);
//FSM EVENTS //FSM EVENTS
void Event_start_acquisition(); bool Event_start_acquisition();
void Event_valid_acquisition(); bool Event_valid_acquisition();
void Event_failed_acquisition_repeat(); bool Event_failed_acquisition_repeat();
void Event_failed_acquisition_no_repeat(); bool Event_failed_acquisition_no_repeat();
void Event_failed_tracking_standby(); bool Event_failed_tracking_standby();
private: private:

View File

@ -44,26 +44,27 @@ channel_msg_receiver_cc_sptr channel_msg_receiver_make_cc(ChannelFsm* channel_fs
void channel_msg_receiver_cc::msg_handler_events(pmt::pmt_t msg) void channel_msg_receiver_cc::msg_handler_events(pmt::pmt_t msg)
{ {
bool result = false;
try try
{ {
long int message = pmt::to_long(msg); long int message = pmt::to_long(msg);
switch (message) switch (message)
{ {
case 1: //positive acquisition case 1: //positive acquisition
d_channel_fsm->Event_valid_acquisition(); result = d_channel_fsm->Event_valid_acquisition();
break; break;
case 2: //negative acquisition case 2: //negative acquisition
if (d_repeat == true) if (d_repeat == true)
{ {
d_channel_fsm->Event_failed_acquisition_repeat(); result = d_channel_fsm->Event_failed_acquisition_repeat();
} }
else else
{ {
d_channel_fsm->Event_failed_acquisition_no_repeat(); result = d_channel_fsm->Event_failed_acquisition_no_repeat();
} }
break; break;
case 3: // tracking loss of lock event case 3: // tracking loss of lock event
d_channel_fsm->Event_failed_tracking_standby(); result = d_channel_fsm->Event_failed_tracking_standby();
break; break;
default: default:
LOG(WARNING) << "Default case, invalid message."; LOG(WARNING) << "Default case, invalid message.";
@ -74,6 +75,10 @@ void channel_msg_receiver_cc::msg_handler_events(pmt::pmt_t msg)
{ {
LOG(WARNING) << "msg_handler_telemetry Bad any cast!"; LOG(WARNING) << "msg_handler_telemetry Bad any cast!";
} }
if(!result)
{
LOG(WARNING) << "msg_handler_telemetry invalid event";
}
} }