From acd7c8519fb86c951a4deb26b97e3ed407b74cbf Mon Sep 17 00:00:00 2001 From: Eric House Date: Sat, 22 Jun 2013 05:56:27 -0700 Subject: [PATCH] give timers ids so can be tracked in logs --- xwords4/relay/timermgr.cpp | 15 +++++++++++---- xwords4/relay/timermgr.h | 2 ++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/xwords4/relay/timermgr.cpp b/xwords4/relay/timermgr.cpp index 41d434300..b1438e7c8 100644 --- a/xwords4/relay/timermgr.cpp +++ b/xwords4/relay/timermgr.cpp @@ -29,6 +29,7 @@ TimerMgr::TimerMgr() : m_nextFireTime(0) + ,m_nextID(0) { pthread_mutex_init( &m_timersMutex, NULL ); } @@ -55,6 +56,7 @@ TimerMgr::SetTimer( time_t inSeconds, TimerProc proc, void* closure, ti.interval = interval; MutexLock ml( &m_timersMutex ); + ti.id = ++m_nextID; if ( getTimer( proc, closure ) ) { logf( XW_LOGINFO, "%s: clearing old timer", __func__ ); @@ -145,6 +147,7 @@ TimerMgr::FireElapsedTimers() vector procs; vector closures; + vector ids; { MutexLock ml( &m_timersMutex ); /* loop until we get through without firing a single one. Only fire one @@ -157,6 +160,7 @@ TimerMgr::FireElapsedTimers() procs.push_back(tip->proc); closures.push_back(tip->closure); + ids.push_back(tip->id); if ( tip->interval ) { tip->when += tip->interval; @@ -167,10 +171,12 @@ TimerMgr::FireElapsedTimers() } } - vector::iterator iter1 = procs.begin(); - vector::iterator iter2 = closures.begin(); - while ( iter1 != procs.end() ) { - (*iter1++)(*iter2++); + vector::const_iterator procs_iter = procs.begin(); + vector::const_iterator closures_iter = closures.begin(); + vector::const_iterator ids_iter = ids.begin(); + while ( procs_iter != procs.end() ) { + logf( XW_LOGINFO, "%s: firing timer id=%d", __func__, *ids_iter++ ); + (*procs_iter++)(*closures_iter++); } MutexLock ml( &m_timersMutex ); @@ -184,6 +190,7 @@ TimerMgr::clearTimerImpl( TimerProc proc, void* closure ) for ( iter = m_timers.begin(); iter != m_timers.end(); ++iter ) { TimerInfo* tip = &(*iter); if ( tip->proc == proc && tip->closure == closure ) { + logf( XW_LOGINFO, "clearing timer id=%d", tip->id ); m_timers.erase(iter); break; } diff --git a/xwords4/relay/timermgr.h b/xwords4/relay/timermgr.h index 841833b71..9236da330 100644 --- a/xwords4/relay/timermgr.h +++ b/xwords4/relay/timermgr.h @@ -51,6 +51,7 @@ class TimerMgr { void* closure; time_t when; int interval; + uint32_t id; } TimerInfo; @@ -65,6 +66,7 @@ class TimerMgr { list m_timers; time_t m_nextFireTime; + uint32_t m_nextID; }; #endif