tools: Use automatic mutex management

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Tim Wiederhake 2022-02-08 14:59:30 +01:00
parent f9c863237f
commit 883cd98498
4 changed files with 20 additions and 25 deletions

View File

@ -613,9 +613,7 @@ int
virFirewallApply(virFirewall *firewall)
{
size_t i, j;
int ret = -1;
virMutexLock(&ruleLock);
VIR_LOCK_GUARD lock = virLockGuardLock(&ruleLock);
if (!firewall || firewall->err) {
int err = EINVAL;
@ -624,7 +622,7 @@ virFirewallApply(virFirewall *firewall)
err = firewall->err;
virReportSystemError(err, "%s", _("Unable to create rule"));
goto cleanup;
return -1;
}
VIR_DEBUG("Applying groups for %p", firewall);
@ -657,13 +655,10 @@ virFirewallApply(virFirewall *firewall)
virErrorRestore(&saved_error);
VIR_DEBUG("Done rolling back groups for %p", firewall);
goto cleanup;
return -1;
}
}
VIR_DEBUG("Done applying groups for %p", firewall);
ret = 0;
cleanup:
virMutexUnlock(&ruleLock);
return ret;
return 0;
}

View File

@ -412,13 +412,13 @@ virshDeinit(vshControl *ctl)
virResetLastError();
if (ctl->eventLoopStarted) {
int timer;
int timer = -1;
virMutexLock(&ctl->lock);
ctl->quit = true;
/* HACK: Add a dummy timeout to break event loop */
timer = virEventAddTimeout(0, virshDeinitTimer, NULL, NULL);
virMutexUnlock(&ctl->lock);
VIR_WITH_MUTEX_LOCK_GUARD(&ctl->lock) {
ctl->quit = true;
/* HACK: Add a dummy timeout to break event loop */
timer = virEventAddTimeout(0, virshDeinitTimer, NULL, NULL);
}
virThreadJoin(&ctl->eventLoop);

View File

@ -1189,13 +1189,13 @@ vshAdmDeinit(vshControl *ctl)
virResetLastError();
if (ctl->eventLoopStarted) {
int timer;
int timer = -1;
virMutexLock(&ctl->lock);
ctl->quit = true;
/* HACK: Add a dummy timeout to break event loop */
timer = virEventAddTimeout(0, vshAdmDeinitTimer, NULL, NULL);
virMutexUnlock(&ctl->lock);
VIR_WITH_MUTEX_LOCK_GUARD(&ctl->lock) {
ctl->quit = true;
/* HACK: Add a dummy timeout to break event loop */
timer = virEventAddTimeout(0, vshAdmDeinitTimer, NULL, NULL);
}
virThreadJoin(&ctl->eventLoop);

View File

@ -2018,10 +2018,10 @@ vshEventLoop(void *opaque)
vshControl *ctl = opaque;
while (1) {
bool quit;
virMutexLock(&ctl->lock);
quit = ctl->quit;
virMutexUnlock(&ctl->lock);
bool quit = false;
VIR_WITH_MUTEX_LOCK_GUARD(&ctl->lock) {
quit = ctl->quit;
}
if (quit)
break;