mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-25 07:05:28 +00:00
De-duplicate code into virObjectEventStateCleanupTimer()
There is a repeating pattern of code that removes the timer if it's not needed. So let's move it to a new function. We'll also use it later. Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
This commit is contained in:
parent
3d279e23e7
commit
6fecf9523a
@ -783,6 +783,25 @@ virObjectEventStateQueue(virObjectEventStatePtr state,
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
virObjectEventStateCleanupTimer(virObjectEventStatePtr state, bool clear_queue)
|
||||
{
|
||||
/* There are still some callbacks, keep the timer. */
|
||||
if (state->callbacks->count)
|
||||
return;
|
||||
|
||||
/* The timer is not registered, nothing to do. */
|
||||
if (state->timer == -1)
|
||||
return;
|
||||
|
||||
virEventRemoveTimeout(state->timer);
|
||||
state->timer = -1;
|
||||
|
||||
if (clear_queue)
|
||||
virObjectEventQueueClear(state->queue);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
virObjectEventStateFlush(virObjectEventStatePtr state)
|
||||
{
|
||||
@ -886,12 +905,8 @@ virObjectEventStateRegisterID(virConnectPtr conn,
|
||||
cb, opaque, freecb,
|
||||
legacy, callbackID, serverFilter);
|
||||
|
||||
if (ret == -1 &&
|
||||
state->callbacks->count == 0 &&
|
||||
state->timer != -1) {
|
||||
virEventRemoveTimeout(state->timer);
|
||||
state->timer = -1;
|
||||
}
|
||||
if (ret < 0)
|
||||
virObjectEventStateCleanupTimer(state, false);
|
||||
|
||||
cleanup:
|
||||
virObjectUnlock(state);
|
||||
@ -926,12 +941,7 @@ virObjectEventStateDeregisterID(virConnectPtr conn,
|
||||
ret = virObjectEventCallbackListRemoveID(conn,
|
||||
state->callbacks, callbackID);
|
||||
|
||||
if (state->callbacks->count == 0 &&
|
||||
state->timer != -1) {
|
||||
virEventRemoveTimeout(state->timer);
|
||||
state->timer = -1;
|
||||
virObjectEventQueueClear(state->queue);
|
||||
}
|
||||
virObjectEventStateCleanupTimer(state, true);
|
||||
|
||||
virObjectUnlock(state);
|
||||
return ret;
|
||||
|
Loading…
Reference in New Issue
Block a user