main: add some (commented out) debug for gtimer and fixed minor issue in gtimercmp

The issue should be benign, equal timers were always reported -1, not right.
This commit is contained in:
Adam Sutton 2013-12-21 22:01:07 +00:00
parent 57b7b33d3a
commit 70bf35b6f6

View file

@ -200,7 +200,7 @@ gtimercmp(gtimer_t *a, gtimer_t *b)
return -1;
if(a->gti_expire.tv_nsec > b->gti_expire.tv_nsec)
return 1;
return -1;
return 0;
}
/**
@ -221,6 +221,8 @@ gtimer_arm_abs2
LIST_INSERT_SORTED(&gtimers, gti, gti_link, gtimercmp);
//tvhdebug("gtimer", "%p @ %ld.%09ld", gti, when->tv_sec, when->tv_nsec);
if (LIST_FIRST(&gtimers) == gti)
pthread_cond_signal(&gtimer_cond); // force timer re-check
}
@ -269,6 +271,7 @@ void
gtimer_disarm(gtimer_t *gti)
{
if(gti->gti_callback) {
//tvhdebug("gtimer", "%p disarm", gti);
LIST_REMOVE(gti, gti_link);
gti->gti_callback = NULL;
}
@ -361,7 +364,15 @@ mainloop(void)
// TODO: there is a risk that if timers re-insert themselves to
// the top of the list with a 0 offset we could loop indefinitely
#if 0
tvhdebug("gtimer", "now %ld.%09ld", ts.tv_sec, ts.tv_nsec);
LIST_FOREACH(gti, &gtimers, gti_link)
tvhdebug("gtimer", " gti %p expire %ld.%08ld",
gti, gti->gti_expire.tv_sec, gti->gti_expire.tv_nsec);
#endif
while((gti = LIST_FIRST(&gtimers)) != NULL) {
if ((gti->gti_expire.tv_sec > ts.tv_sec) ||
((gti->gti_expire.tv_sec == ts.tv_sec) &&
(gti->gti_expire.tv_nsec > ts.tv_nsec))) {
@ -370,6 +381,7 @@ mainloop(void)
}
cb = gti->gti_callback;
//tvhdebug("gtimer", "%p callback", gti);
LIST_REMOVE(gti, gti_link);
gti->gti_callback = NULL;
@ -384,6 +396,7 @@ mainloop(void)
}
/* Wait */
//tvhdebug("gtimer", "wait till %ld.%09ld", ts.tv_sec, ts.tv_nsec);
pthread_cond_timedwait(&gtimer_cond, &global_lock, &ts);
pthread_mutex_unlock(&global_lock);
}