From: g0dil Date: Tue, 28 Aug 2007 07:23:52 +0000 (+0000) Subject: Scheduler: BUGFIX: Restart itimer after clock-skew detection X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=ffa36b2d409289a2f3f0de46667aa2bf558f393f;p=senf.git Scheduler: BUGFIX: Restart itimer after clock-skew detection git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@411 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/Scheduler/ClockService.cc b/Scheduler/ClockService.cc index a614462..f31ec4f 100644 --- a/Scheduler/ClockService.cc +++ b/Scheduler/ClockService.cc @@ -125,14 +125,19 @@ prefix_ void senf::ClockService::restart_m(bool restart) action.sa_flags = SA_RESTART; CheckError( sigaction, (SIGALRM, &action, restart ? 0 : &impl_->oldaction) ); + restartTimer(restart); + + impl_->unblock(); +} + +prefix_ void senf::ClockService::restartTimer(bool restart) +{ struct itimerval itimer; itimer.it_interval.tv_sec = CheckInterval; itimer.it_interval.tv_usec = 0; itimer.it_value.tv_sec = CheckInterval; itimer.it_value.tv_usec = 0; CheckError( setitimer, (ITIMER_REAL, &itimer, restart ? 0 : &impl_->olditimer) ); - - impl_->unblock(); } prefix_ void senf::ClockService::updateSkew(boost::posix_time::ptime time) @@ -149,6 +154,8 @@ prefix_ void senf::ClockService::updateSkew(boost::posix_time::ptime time) + boost::posix_time::seconds(CheckInterval) - boost::posix_time::seconds(itimer.it_value.tv_sec) - boost::posix_time::microseconds(itimer.it_value.tv_usec))); + heartbeat_ = time; + restartTimer(); } } diff --git a/Scheduler/ClockService.hh b/Scheduler/ClockService.hh index 21a15eb..b2cf6db 100644 --- a/Scheduler/ClockService.hh +++ b/Scheduler/ClockService.hh @@ -154,6 +154,8 @@ namespace senf { void updateSkew(boost::posix_time::ptime time); void clockSkew(boost::posix_time::ptime time, boost::posix_time::ptime expected); + void restartTimer(bool restart = true); + boost::posix_time::ptime base_; boost::posix_time::ptime heartbeat_; diff --git a/Scheduler/ClockService.test.cc b/Scheduler/ClockService.test.cc index 88c68e9..fbbe5ab 100644 --- a/Scheduler/ClockService.test.cc +++ b/Scheduler/ClockService.test.cc @@ -117,10 +117,13 @@ BOOST_AUTO_UNIT_TEST(clockService) BOOST_CHECK_PREDICATE( is_close_clock, (t1 + senf::ClockService::milliseconds(200)) (senf::ClockService::now()) ); - - // We need restart the clock-service here to fix up the bad heartbeat value. That's faster - // than waiting another CheckInterval seconds for SIGALRM - senf::ClockService::restart(); + + // The next check validates that the clock service itimer/heartbeat_ is correctly reset after a + // clock-skew is detected + + BOOST_CHECK_PREDICATE( is_close_clock, + (t1 + senf::ClockService::milliseconds(200)) + (senf::ClockService::now()) ); } ///////////////////////////////cc.e////////////////////////////////////////