mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-30 10:26:58 +01:00
give timers ids so can be tracked in logs
This commit is contained in:
parent
07d6851a26
commit
acd7c8519f
2 changed files with 13 additions and 4 deletions
|
@ -29,6 +29,7 @@
|
||||||
|
|
||||||
TimerMgr::TimerMgr()
|
TimerMgr::TimerMgr()
|
||||||
: m_nextFireTime(0)
|
: m_nextFireTime(0)
|
||||||
|
,m_nextID(0)
|
||||||
{
|
{
|
||||||
pthread_mutex_init( &m_timersMutex, NULL );
|
pthread_mutex_init( &m_timersMutex, NULL );
|
||||||
}
|
}
|
||||||
|
@ -55,6 +56,7 @@ TimerMgr::SetTimer( time_t inSeconds, TimerProc proc, void* closure,
|
||||||
ti.interval = interval;
|
ti.interval = interval;
|
||||||
|
|
||||||
MutexLock ml( &m_timersMutex );
|
MutexLock ml( &m_timersMutex );
|
||||||
|
ti.id = ++m_nextID;
|
||||||
|
|
||||||
if ( getTimer( proc, closure ) ) {
|
if ( getTimer( proc, closure ) ) {
|
||||||
logf( XW_LOGINFO, "%s: clearing old timer", __func__ );
|
logf( XW_LOGINFO, "%s: clearing old timer", __func__ );
|
||||||
|
@ -145,6 +147,7 @@ TimerMgr::FireElapsedTimers()
|
||||||
|
|
||||||
vector<TimerProc> procs;
|
vector<TimerProc> procs;
|
||||||
vector<void*> closures;
|
vector<void*> closures;
|
||||||
|
vector<uint32_t> ids;
|
||||||
{
|
{
|
||||||
MutexLock ml( &m_timersMutex );
|
MutexLock ml( &m_timersMutex );
|
||||||
/* loop until we get through without firing a single one. Only fire one
|
/* loop until we get through without firing a single one. Only fire one
|
||||||
|
@ -157,6 +160,7 @@ TimerMgr::FireElapsedTimers()
|
||||||
|
|
||||||
procs.push_back(tip->proc);
|
procs.push_back(tip->proc);
|
||||||
closures.push_back(tip->closure);
|
closures.push_back(tip->closure);
|
||||||
|
ids.push_back(tip->id);
|
||||||
|
|
||||||
if ( tip->interval ) {
|
if ( tip->interval ) {
|
||||||
tip->when += tip->interval;
|
tip->when += tip->interval;
|
||||||
|
@ -167,10 +171,12 @@ TimerMgr::FireElapsedTimers()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<TimerProc>::iterator iter1 = procs.begin();
|
vector<TimerProc>::const_iterator procs_iter = procs.begin();
|
||||||
vector<void*>::iterator iter2 = closures.begin();
|
vector<void*>::const_iterator closures_iter = closures.begin();
|
||||||
while ( iter1 != procs.end() ) {
|
vector<uint32_t>::const_iterator ids_iter = ids.begin();
|
||||||
(*iter1++)(*iter2++);
|
while ( procs_iter != procs.end() ) {
|
||||||
|
logf( XW_LOGINFO, "%s: firing timer id=%d", __func__, *ids_iter++ );
|
||||||
|
(*procs_iter++)(*closures_iter++);
|
||||||
}
|
}
|
||||||
|
|
||||||
MutexLock ml( &m_timersMutex );
|
MutexLock ml( &m_timersMutex );
|
||||||
|
@ -184,6 +190,7 @@ TimerMgr::clearTimerImpl( TimerProc proc, void* closure )
|
||||||
for ( iter = m_timers.begin(); iter != m_timers.end(); ++iter ) {
|
for ( iter = m_timers.begin(); iter != m_timers.end(); ++iter ) {
|
||||||
TimerInfo* tip = &(*iter);
|
TimerInfo* tip = &(*iter);
|
||||||
if ( tip->proc == proc && tip->closure == closure ) {
|
if ( tip->proc == proc && tip->closure == closure ) {
|
||||||
|
logf( XW_LOGINFO, "clearing timer id=%d", tip->id );
|
||||||
m_timers.erase(iter);
|
m_timers.erase(iter);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,6 +51,7 @@ class TimerMgr {
|
||||||
void* closure;
|
void* closure;
|
||||||
time_t when;
|
time_t when;
|
||||||
int interval;
|
int interval;
|
||||||
|
uint32_t id;
|
||||||
} TimerInfo;
|
} TimerInfo;
|
||||||
|
|
||||||
|
|
||||||
|
@ -65,6 +66,7 @@ class TimerMgr {
|
||||||
list<TimerInfo> m_timers;
|
list<TimerInfo> m_timers;
|
||||||
|
|
||||||
time_t m_nextFireTime;
|
time_t m_nextFireTime;
|
||||||
|
uint32_t m_nextID;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue