Module: sems
Branch: master
Commit: 25a1cdc8b37eceeadabe565a1821100be14ffaeb
URL:    
http://git.sip-router.org/cgi-bin/gitweb.cgi/sems/?a=commit;h=25a1cdc8b37eceeadabe565a1821100be14ffaeb

Author: Stefan Sayer <[email protected]>
Committer: Stefan Sayer <[email protected]>
Date:   Thu Aug  9 11:00:08 2012 +0200

b/f: db_reg_agent: also stop RegistrationTimer thread on unclean shutdown

---

 apps/db_reg_agent/DBRegAgent.cpp        |   12 +++++++-----
 apps/db_reg_agent/RegistrationTimer.cpp |    4 ++++
 apps/db_reg_agent/RegistrationTimer.h   |    1 +
 3 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/apps/db_reg_agent/DBRegAgent.cpp b/apps/db_reg_agent/DBRegAgent.cpp
index 74e3c7e..168f89a 100644
--- a/apps/db_reg_agent/DBRegAgent.cpp
+++ b/apps/db_reg_agent/DBRegAgent.cpp
@@ -242,13 +242,15 @@ int DBRegAgent::onLoad()
 void DBRegAgent::onUnload() {
   if (running) {
     running = false;
+    registration_scheduler._timer_thread_running = false;
     DBG("unclean shutdown. Waiting for processing thread to stop.\n");
-    for (int i=0;i<20;i++) {
-      if (shutdown_finished)
+    for (int i=0;i<400;i++) {
+      if (shutdown_finished && registration_scheduler._shutdown_finished)
        break;
       usleep(2000); // 2ms
     }
-    if (!shutdown_finished) {
+
+    if (!shutdown_finished || !registration_scheduler._shutdown_finished) {
       WARN("processing thread could not be stopped, process will probably 
crash\n");
     }
   }
@@ -880,7 +882,7 @@ void DBRegAgent::onSipReplyEvent(AmSipReplyEvent* ev) {
 }
 
 void DBRegAgent::run() {
-  running = true;
+  running = shutdown_finished = true;
 
   DBG("DBRegAgent thread: waiting 2 sec for server startup ...\n");
   sleep(2);
@@ -892,8 +894,8 @@ void DBRegAgent::run() {
     registration_processor.start();
   }
 
-  shutdown_finished = false;
   DBG("running DBRegAgent thread...\n");
+  shutdown_finished = false;
   while (running) {
     processEvents();
 
diff --git a/apps/db_reg_agent/RegistrationTimer.cpp 
b/apps/db_reg_agent/RegistrationTimer.cpp
index dcd3e54..79d5be3 100644
--- a/apps/db_reg_agent/RegistrationTimer.cpp
+++ b/apps/db_reg_agent/RegistrationTimer.cpp
@@ -196,6 +196,7 @@ void RegistrationTimer::run_timers() {
 void RegistrationTimer::run()
 {
   struct timeval now,next_tick,diff,tick;
+  _shutdown_finished = false;
 
   tick.tv_sec = 0;
   tick.tv_usec = TIMER_RESOLUTION;
@@ -227,6 +228,9 @@ void RegistrationTimer::run()
     run_timers();
     timeradd(&tick,&next_tick,&next_tick);
   }
+
+  DBG("RegistrationTimer thread finishing.\n");
+  _shutdown_finished = true;
 }
 
 void RegistrationTimer::on_stop() {
diff --git a/apps/db_reg_agent/RegistrationTimer.h 
b/apps/db_reg_agent/RegistrationTimer.h
index 27eb072..c39fb1e 100644
--- a/apps/db_reg_agent/RegistrationTimer.h
+++ b/apps/db_reg_agent/RegistrationTimer.h
@@ -109,6 +109,7 @@ class RegistrationTimer
 
   RegistrationTimer(); 
   bool _timer_thread_running;
+  bool _shutdown_finished;
 };
 
 #endif

_______________________________________________
Semsdev mailing list
[email protected]
http://lists.iptel.org/mailman/listinfo/semsdev

Reply via email to