Changed TimerEventProxy to update the timeout when adding an TimerEvent already included.
ssauer [Thu, 20 Jan 2011 12:41:31 +0000 (12:41 +0000)]
git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1768 270642c3-0616-0410-b53a-bc976706d245

senf/Scheduler/TimerEventProxy.ct
senf/Scheduler/TimerEventProxy.test.cc

index 666f30a..3061b73 100644 (file)
@@ -59,8 +59,15 @@ template<typename IdType>
 prefix_ void senf::scheduler::TimerEventProxy<IdType>::add(
         ClockService::clock_type timeout, IdType const & id, Callback cb)
 {
-    // insert new entry
-    entrySetByTimeout.insert( Entry(timeout, id, cb));
+    // insert new entry or replace the timeout of an entry already indexed
+    typename EntrySetById_t::iterator i = entrySetById.find(id);
+    if(i == entrySetById.end())
+       entrySetByTimeout.insert( Entry(timeout, id, cb));
+       else{
+               Entry tmp = *i;
+               tmp.timeout = timeout;
+               entrySetById.replace(i,tmp);
+       }
     // the scheduler time to the first earliest timeout (ordered index)
     timer.timeout( entrySetByTimeout.begin()->timeout);
 }
index 0710247..ed39af8 100644 (file)
@@ -72,6 +72,9 @@ SENF_AUTO_UNIT_TEST(timerEventProxy)
 
         BOOST_CHECK_EQUAL( timers.timeout(1), t + senf::ClockService::milliseconds(200));
         BOOST_CHECK_EQUAL( timers.timeout(2), t + senf::ClockService::milliseconds(700));
+
+        timers.add( t + senf::ClockService::milliseconds(800), 2, &handler);
+        BOOST_CHECK_EQUAL( timers.timeout(2), t + senf::ClockService::milliseconds(800));
         BOOST_CHECK_EQUAL( timers.timeout(4), 0);
 
         run( senf::ClockService::milliseconds( 2000));