qemu-timer: introduce timer_deinit

In some cases, a timer was set to NULL so that we could check if it is
initialized.  Use the timer_list field instead, and add a timer_deinit
function that NULLs it.

It then makes sense that timer_del be a no-op (instead of a crasher) on
such a de-initialized timer.  It avoids the need to poke at the timerlist
field to check if the timers are initialized.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Paolo Bonzini 2014-12-24 10:57:04 +01:00
parent 65a81af8df
commit cd1bd53a66
2 changed files with 22 additions and 3 deletions

View file

@ -594,6 +594,17 @@ static inline QEMUTimer *timer_new_ms(QEMUClockType type, QEMUTimerCB *cb,
return timer_new(type, SCALE_MS, cb, opaque);
}
/**
* timer_deinit:
* @ts: the timer to be de-initialised
*
* Deassociate the timer from any timerlist. You should
* call timer_del before. After this call, any further
* timer_del call cannot cause dangling pointer accesses
* even if the previously used timerlist is freed.
*/
void timer_deinit(QEMUTimer *ts);
/**
* timer_free:
* @ts: the timer