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

Author: Stefan Sayer <[email protected]>
Committer: Stefan Sayer <[email protected]>
Date:   Sat Jun 19 17:16:01 2010 +0200

avoid deadlock when setting timer in timer event

when using user timers, new timers can now be set and current timers
removed when processing the timer event (i.e. directly in the postEvent
function - which should not be blocking for long time anyway)

---

 core/plug-in/session_timer/UserTimer.cpp |   25 +++++++++++++++++--------
 1 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/core/plug-in/session_timer/UserTimer.cpp 
b/core/plug-in/session_timer/UserTimer.cpp
index b78b97c..65ca42e 100644
--- a/core/plug-in/session_timer/UserTimer.cpp
+++ b/core/plug-in/session_timer/UserTimer.cpp
@@ -70,6 +70,8 @@ bool operator < (const AmTimer& l, const AmTimer& r)
 }
 
 void UserTimer::checkTimers() {
+  vector<std::pair<string, int> > expired_timers;
+
   timers_mut.lock();
   if(timers.empty()){
     timers_mut.unlock();
@@ -87,19 +89,26 @@ void UserTimer::checkTimers() {
     string session_id = it->session_id;
     // erase
     timers.erase(it);
-    // 'fire' timer      
-    if (!AmSessionContainer::instance()->postEvent(session_id, 
-                                                  new AmTimeoutEvent(id))) {
-      DBG("Timeout Event could not be posted, session does not exist any 
more.\n");
-    }
-    else {
-      DBG("Timeout Event could be posted.\n");
-    }
+    expired_timers.push_back(make_pair(session_id, id));
     
     if(timers.empty()) break;
     it = timers.begin();
   }
   timers_mut.unlock();
+
+  for (vector<std::pair<string, int> >::iterator e_it =
+        expired_timers.begin(); e_it != expired_timers.end(); e_it++) {
+    // 'fire' timer
+    if (!AmSessionContainer::instance()->postEvent(e_it->first, 
+                                                  new 
AmTimeoutEvent(e_it->second))) {
+      DBG("Timeout Event '%d' could not be posted, session '%s' does not exist 
any more.\n",
+         e_it->second, e_it->first.c_str());
+    }
+    else {
+      DBG("Timeout Event '%d' posted to %s.\n", 
+         e_it->second, e_it->first.c_str());
+    }
+  }
 }
 
 void UserTimer::setTimer(int id, int seconds, const string& session_id) {

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

Reply via email to