Browse Source

线程内添加catch...

zzj 6 years ago
parent
commit
fdee643103
4 changed files with 36 additions and 14 deletions
  1. 5 0
      .gitignore
  2. 6 6
      ant.h
  3. 10 7
      module_service/module_i_thread.h
  4. 15 1
      worker.cpp

+ 5 - 0
.gitignore

@@ -34,5 +34,10 @@ config_file.h
 log.h
 struct_def.h
 three_rates.h
+config.guess
+config.sub
+libtool
+three_rates_module
+
 
 

+ 6 - 6
ant.h

@@ -109,16 +109,16 @@ struct site:point,std::enable_shared_from_this<site>
     std::shared_ptr<area> m_area=nullptr;
 
 	time_t m_time;
-    time_t m_rec_time;              // 接收数据的时间
-    time_t m_lost_time;		        // 丢失时间
-    time_t m_last_send_time;	    // 最后向前端发送时间
+//  time_t m_rec_time;              // 接收数据的时间
+//  time_t m_lost_time;		        // 丢失时间
+//  time_t m_last_send_time;	    // 最后向前端发送时间
 	char m_timestamp[8]={0};
 
     int m_id{-1};
-    int  m_tick_count;			    // 分站发生消息的计数器
+//  int  m_tick_count;			    // 分站发生消息的计数器
 
-    unsigned char m_reader_dir;		// 分站方向,对于大小分站适用
-    unsigned char m_relay_counts;		// 大小分站经过中继数
+//  unsigned char m_reader_dir;		// 分站方向,对于大小分站适用
+//  unsigned char m_relay_counts;		// 大小分站经过中继数
     bool m_power_check_enable=false;//该分站是否启用交流掉电检测功能(告警功能)
     bool m_power_ac_down=false;     //false=交流电供电状态
     bool m_path_empty;

+ 10 - 7
module_service/module_i_thread.h

@@ -4,7 +4,7 @@
 #include<atomic>
 #include<boost/thread.hpp>
 #include<mutex>
-//#include<log.h>
+#include<log.h>
 
 /**
  * @brief 线程接口类,重写run函数,改变睡眠时间 sleep_ms
@@ -63,16 +63,19 @@ private:
             try
             {
                 run();
-
                 boost::this_thread::sleep_for(boost::chrono::milliseconds(sleep_ms));
             }
-            catch (boost::thread_interrupted&)
-            {
-            }
-            catch(std::exception&)
+            catch (const boost::thread_interrupted&)
             {
-                //log_error("thread_proc exception 结束线程 i_thread");
             }
+			catch(const std::exception&e)
+			{
+				log_error("捕获到异常:%s",e.what());
+			}
+			catch(...)
+			{
+				log_error("捕获到未知异常");
+			}
         }
     }
 };

+ 15 - 1
worker.cpp

@@ -57,7 +57,21 @@ struct worker_thread: zloop<task*> ,visitor<std::shared_ptr<card_location_base>>
 		card_timer_1s.set<worker_thread,&worker_thread::on_timeout>(this);
 		card_timer_1s.start(1,1);
 
-		ev::dynamic_loop::run(0);
+		while(!check_stop_flag())
+		{
+			try
+			{
+				ev::dynamic_loop::run(0);
+			}
+			catch(const std::exception&e)
+			{
+				log_error("捕获到异常:%s",e.what());
+			}
+			catch(...)
+			{
+				log_error("捕获到未知异常");
+			}
+		}
 		log_info("worker_thread exit....");
 	}