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()
{
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()";
}

View File

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

View File

@ -54,11 +54,11 @@ public:
void set_channel(unsigned int channel);
//FSM EVENTS
void Event_start_acquisition();
void Event_valid_acquisition();
void Event_failed_acquisition_repeat();
void Event_failed_acquisition_no_repeat();
void Event_failed_tracking_standby();
bool Event_start_acquisition();
bool Event_valid_acquisition();
bool Event_failed_acquisition_repeat();
bool Event_failed_acquisition_no_repeat();
bool Event_failed_tracking_standby();
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)
{
bool result = false;
try
{
long int message = pmt::to_long(msg);
switch (message)
{
case 1: //positive acquisition
d_channel_fsm->Event_valid_acquisition();
result = d_channel_fsm->Event_valid_acquisition();
break;
case 2: //negative acquisition
if (d_repeat == true)
{
d_channel_fsm->Event_failed_acquisition_repeat();
result = d_channel_fsm->Event_failed_acquisition_repeat();
}
else
{
d_channel_fsm->Event_failed_acquisition_no_repeat();
result = d_channel_fsm->Event_failed_acquisition_no_repeat();
}
break;
case 3: // tracking loss of lock event
d_channel_fsm->Event_failed_tracking_standby();
result = d_channel_fsm->Event_failed_tracking_standby();
break;
default:
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!";
}
if(!result)
{
LOG(WARNING) << "msg_handler_telemetry invalid event";
}
}