mirror of
				https://github.com/gnss-sdr/gnss-sdr
				synced 2025-10-31 15:23:04 +00:00 
			
		
		
		
	Avoid multithreading collision
This commit is contained in:
		| @@ -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()"; | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -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); | ||||||
|  |     if((d_state == 1) || (d_state == 2)) | ||||||
|  |         { | ||||||
|  |             return false; | ||||||
|  |         } | ||||||
|  |     else | ||||||
|  |         { | ||||||
|             d_state = 1; |             d_state = 1; | ||||||
|             start_acquisition(); |             start_acquisition(); | ||||||
|             DLOG(INFO) << "CH = " << channel_ << ". Ev start acquisition"; |             DLOG(INFO) << "CH = " << channel_ << ". Ev start acquisition"; | ||||||
|     mx.unlock(); |             return true; | ||||||
|  |         } | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| void ChannelFsm::Event_valid_acquisition() | bool ChannelFsm::Event_valid_acquisition() | ||||||
| { | { | ||||||
|     mx.lock(); |     std::lock_guard<std::mutex> lk(mx); | ||||||
|  |     if(d_state != 1) | ||||||
|  |         { | ||||||
|  |             return false; | ||||||
|  |         } | ||||||
|  |     else | ||||||
|  |         { | ||||||
|             d_state = 2; |             d_state = 2; | ||||||
|             start_tracking(); |             start_tracking(); | ||||||
|             DLOG(INFO) << "CH = " << channel_ << ". Ev valid acquisition"; |             DLOG(INFO) << "CH = " << channel_ << ". Ev valid acquisition"; | ||||||
|     mx.unlock(); |             return true; | ||||||
|  |         } | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| void ChannelFsm::Event_failed_acquisition_repeat() | bool ChannelFsm::Event_failed_acquisition_repeat() | ||||||
| { | { | ||||||
|     mx.lock(); |     std::lock_guard<std::mutex> lk(mx); | ||||||
|  |     if(d_state != 1) | ||||||
|  |         { | ||||||
|  |             return false; | ||||||
|  |         } | ||||||
|  |     else | ||||||
|  |         { | ||||||
|             d_state = 1; |             d_state = 1; | ||||||
|             start_acquisition(); |             start_acquisition(); | ||||||
|             DLOG(INFO) << "CH = " << channel_ << ". Ev failed acquisition repeat"; |             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() | ||||||
| { | { | ||||||
|     mx.lock(); |     std::lock_guard<std::mutex> lk(mx); | ||||||
|  |     if(d_state != 1) | ||||||
|  |         { | ||||||
|  |             return false; | ||||||
|  |         } | ||||||
|  |     else | ||||||
|  |         { | ||||||
|             d_state = 3; |             d_state = 3; | ||||||
|             request_satellite(); |             request_satellite(); | ||||||
|             DLOG(INFO) << "CH = " << channel_ << ". Ev failed acquisition no repeat"; |             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() | ||||||
| { | { | ||||||
|     mx.lock(); |     std::lock_guard<std::mutex> lk(mx); | ||||||
|  |     if(d_state != 2) | ||||||
|  |         { | ||||||
|  |             return false; | ||||||
|  |         } | ||||||
|  |     else | ||||||
|  |         { | ||||||
|             d_state = 0; |             d_state = 0; | ||||||
|             notify_stop_tracking(); |             notify_stop_tracking(); | ||||||
|             DLOG(INFO) << "CH = " << channel_ << ". Ev failed tracking standby"; |             DLOG(INFO) << "CH = " << channel_ << ". Ev failed tracking standby"; | ||||||
|     mx.unlock(); |             return true; | ||||||
|  |         } | ||||||
| } | } | ||||||
|  |  | ||||||
| void ChannelFsm::set_acquisition(std::shared_ptr<AcquisitionInterface> acquisition) | void ChannelFsm::set_acquisition(std::shared_ptr<AcquisitionInterface> acquisition) | ||||||
|   | |||||||
| @@ -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: | ||||||
|  |  | ||||||
|   | |||||||
| @@ -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"; | ||||||
|  |         } | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Antonio Ramos
					Antonio Ramos