Author: sayer
Date: 2009-02-10 14:22:18 +0100 (Tue, 10 Feb 2009)
New Revision: 1265

Modified:
   branches/1.0/core/plug-in/sipctrl/wheeltimer.cpp
   branches/1.0/core/plug-in/sipctrl/wheeltimer.h
Log:
fixes a race condition between timer insertion and deletion.
Thx to Peter Loeppky for contributing this path. (backport from trunk r1224)

Modified: branches/1.0/core/plug-in/sipctrl/wheeltimer.cpp
===================================================================
--- branches/1.0/core/plug-in/sipctrl/wheeltimer.cpp    2009-02-10 13:02:07 UTC 
(rev 1264)
+++ branches/1.0/core/plug-in/sipctrl/wheeltimer.cpp    2009-02-10 13:22:18 UTC 
(rev 1265)
@@ -64,9 +64,9 @@
 void wheeltimer::insert_timer(timer* t)
 {
     //add new timer to user request list
-    utimer_add_m.lock();
+    utimer_m.lock();
     utimer_add.push(t);
-    utimer_add_m.unlock();
+    utimer_m.unlock();
 }
 
 void wheeltimer::remove_timer(timer* t)
@@ -74,9 +74,9 @@
     //DBG("wheeltimer::remove_timer(%p)\n",t);
 
     //add new timer to user request list
-    utimer_rem_m.lock();
+    utimer_m.lock();
     utimer_rem.push(t);
-    utimer_rem_m.unlock();
+    utimer_m.unlock();
 }
 
 void wheeltimer::run()
@@ -157,20 +157,18 @@
     update_wheel(i);
        
     // Check for timer insertion requests
-    utimer_add_m.lock();
+    utimer_m.lock();
     while(!utimer_add.empty()) {
        place_timer(utimer_add.front());
        utimer_add.pop();
     }
-    utimer_add_m.unlock();
        
     // Check for timer deletion requests
-    utimer_rem_m.lock();
     while(!utimer_rem.empty()) {
        delete_timer(utimer_rem.front());
        utimer_rem.pop();
     }
-    utimer_rem_m.unlock();
+    utimer_m.unlock();
        
     //DBG("time = %d\n", wall_clock);
        

Modified: branches/1.0/core/plug-in/sipctrl/wheeltimer.h
===================================================================
--- branches/1.0/core/plug-in/sipctrl/wheeltimer.h      2009-02-10 13:02:07 UTC 
(rev 1264)
+++ branches/1.0/core/plug-in/sipctrl/wheeltimer.h      2009-02-10 13:22:18 UTC 
(rev 1265)
@@ -89,13 +89,14 @@
     //the timer wheel
     base_timer wheels[WHEELS][ELMTS_PER_WHEEL];
 
+    // utimer add/remove lock
+    AmMutex    utimer_m;
+
     //list with timer insertions requests
     std::queue<timer*> utimer_add;
-    AmMutex    utimer_add_m;
 
     //list with timer deletions requests
     std::queue<timer*> utimer_rem;
-    AmMutex    utimer_rem_m;
 
     //list with expired timers
     base_timer utimer_expired;

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

Reply via email to