From: ssauer Date: Thu, 20 Jan 2011 12:41:31 +0000 (+0000) Subject: Changed TimerEventProxy to update the timeout when adding an TimerEvent already included. X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=566fb4271b2aff5aa07943707f770b2a84c2738b;p=senf.git Changed TimerEventProxy to update the timeout when adding an TimerEvent already included. git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1768 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/senf/Scheduler/TimerEventProxy.ct b/senf/Scheduler/TimerEventProxy.ct index 666f30a..3061b73 100644 --- a/senf/Scheduler/TimerEventProxy.ct +++ b/senf/Scheduler/TimerEventProxy.ct @@ -59,8 +59,15 @@ template prefix_ void senf::scheduler::TimerEventProxy::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); } diff --git a/senf/Scheduler/TimerEventProxy.test.cc b/senf/Scheduler/TimerEventProxy.test.cc index 0710247..ed39af8 100644 --- a/senf/Scheduler/TimerEventProxy.test.cc +++ b/senf/Scheduler/TimerEventProxy.test.cc @@ -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));