From 30cf3a30db4ff40d001df9cebfc48450085203be Mon Sep 17 00:00:00 2001 From: imaginos Date: Sat, 20 Jan 2007 11:20:58 +0000 Subject: [PATCH] pull the cron time() call up a level to trim some of the overhead off git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@787 726aef4b-f618-498e-8847-2d620e286838 --- Csocket.cpp | 9 +++++---- Csocket.h | 5 +++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Csocket.cpp b/Csocket.cpp index a4f270a3..f686b7ad 100644 --- a/Csocket.cpp +++ b/Csocket.cpp @@ -303,19 +303,19 @@ CCron::CCron() m_bPause = false; } -void CCron::run() +void CCron::run( time_t iNow ) { if ( m_bPause ) return; - if ( ( m_bActive ) && ( time( NULL ) >= m_iTime ) ) + if ( ( m_bActive ) && ( iNow >= m_iTime ) ) { RunJob(); if ( ( m_iMaxCycles > 0 ) && ( ++m_iCycles >= m_iMaxCycles ) ) m_bActive = false; else - m_iTime = time( NULL ) + m_iTimeSequence; + m_iTime = iNow + m_iTimeSequence; } } @@ -1657,6 +1657,7 @@ unsigned long long Csock::GetRateTime() { return( m_iMaxMilliSeconds ); } void Csock::Cron() { + time_t iNow = time( NULL ); for( vector::size_type a = 0; a < m_vcCrons.size(); a++ ) { CCron *pcCron = m_vcCrons[a]; @@ -1666,7 +1667,7 @@ void Csock::Cron() CS_Delete( pcCron ); m_vcCrons.erase( m_vcCrons.begin() + a-- ); } else - pcCron->run(); + pcCron->run( iNow ); } } diff --git a/Csocket.h b/Csocket.h index 8d33881c..5fa5a488 100644 --- a/Csocket.h +++ b/Csocket.h @@ -366,7 +366,7 @@ public: virtual ~CCron() {} //! This is used by the Job Manager, and not you directly - void run(); + void run( time_t iNow ); /** * @param TimeSequence how often to run in seconds @@ -1994,6 +1994,7 @@ private: //! these crons get ran and checked in Loop() virtual void Cron() { + time_t iNow = time( NULL ); for( unsigned int a = 0; a < m_vcCrons.size(); a++ ) { CCron *pcCron = m_vcCrons[a]; @@ -2003,7 +2004,7 @@ private: CS_Delete( pcCron ); m_vcCrons.erase( m_vcCrons.begin() + a-- ); } else - pcCron->run(); + pcCron->run( iNow ); } }