mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 17:34:18 +03:00
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:
parent
f9c863237f
commit
883cd98498
@ -613,9 +613,7 @@ int
|
|||||||
virFirewallApply(virFirewall *firewall)
|
virFirewallApply(virFirewall *firewall)
|
||||||
{
|
{
|
||||||
size_t i, j;
|
size_t i, j;
|
||||||
int ret = -1;
|
VIR_LOCK_GUARD lock = virLockGuardLock(&ruleLock);
|
||||||
|
|
||||||
virMutexLock(&ruleLock);
|
|
||||||
|
|
||||||
if (!firewall || firewall->err) {
|
if (!firewall || firewall->err) {
|
||||||
int err = EINVAL;
|
int err = EINVAL;
|
||||||
@ -624,7 +622,7 @@ virFirewallApply(virFirewall *firewall)
|
|||||||
err = firewall->err;
|
err = firewall->err;
|
||||||
|
|
||||||
virReportSystemError(err, "%s", _("Unable to create rule"));
|
virReportSystemError(err, "%s", _("Unable to create rule"));
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
VIR_DEBUG("Applying groups for %p", firewall);
|
VIR_DEBUG("Applying groups for %p", firewall);
|
||||||
@ -657,13 +655,10 @@ virFirewallApply(virFirewall *firewall)
|
|||||||
|
|
||||||
virErrorRestore(&saved_error);
|
virErrorRestore(&saved_error);
|
||||||
VIR_DEBUG("Done rolling back groups for %p", firewall);
|
VIR_DEBUG("Done rolling back groups for %p", firewall);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
VIR_DEBUG("Done applying groups for %p", firewall);
|
VIR_DEBUG("Done applying groups for %p", firewall);
|
||||||
|
|
||||||
ret = 0;
|
return 0;
|
||||||
cleanup:
|
|
||||||
virMutexUnlock(&ruleLock);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
@ -412,13 +412,13 @@ virshDeinit(vshControl *ctl)
|
|||||||
virResetLastError();
|
virResetLastError();
|
||||||
|
|
||||||
if (ctl->eventLoopStarted) {
|
if (ctl->eventLoopStarted) {
|
||||||
int timer;
|
int timer = -1;
|
||||||
|
|
||||||
virMutexLock(&ctl->lock);
|
VIR_WITH_MUTEX_LOCK_GUARD(&ctl->lock) {
|
||||||
ctl->quit = true;
|
ctl->quit = true;
|
||||||
/* HACK: Add a dummy timeout to break event loop */
|
/* HACK: Add a dummy timeout to break event loop */
|
||||||
timer = virEventAddTimeout(0, virshDeinitTimer, NULL, NULL);
|
timer = virEventAddTimeout(0, virshDeinitTimer, NULL, NULL);
|
||||||
virMutexUnlock(&ctl->lock);
|
}
|
||||||
|
|
||||||
virThreadJoin(&ctl->eventLoop);
|
virThreadJoin(&ctl->eventLoop);
|
||||||
|
|
||||||
|
@ -1189,13 +1189,13 @@ vshAdmDeinit(vshControl *ctl)
|
|||||||
virResetLastError();
|
virResetLastError();
|
||||||
|
|
||||||
if (ctl->eventLoopStarted) {
|
if (ctl->eventLoopStarted) {
|
||||||
int timer;
|
int timer = -1;
|
||||||
|
|
||||||
virMutexLock(&ctl->lock);
|
VIR_WITH_MUTEX_LOCK_GUARD(&ctl->lock) {
|
||||||
ctl->quit = true;
|
ctl->quit = true;
|
||||||
/* HACK: Add a dummy timeout to break event loop */
|
/* HACK: Add a dummy timeout to break event loop */
|
||||||
timer = virEventAddTimeout(0, vshAdmDeinitTimer, NULL, NULL);
|
timer = virEventAddTimeout(0, vshAdmDeinitTimer, NULL, NULL);
|
||||||
virMutexUnlock(&ctl->lock);
|
}
|
||||||
|
|
||||||
virThreadJoin(&ctl->eventLoop);
|
virThreadJoin(&ctl->eventLoop);
|
||||||
|
|
||||||
|
@ -2018,10 +2018,10 @@ vshEventLoop(void *opaque)
|
|||||||
vshControl *ctl = opaque;
|
vshControl *ctl = opaque;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
bool quit;
|
bool quit = false;
|
||||||
virMutexLock(&ctl->lock);
|
VIR_WITH_MUTEX_LOCK_GUARD(&ctl->lock) {
|
||||||
quit = ctl->quit;
|
quit = ctl->quit;
|
||||||
virMutexUnlock(&ctl->lock);
|
}
|
||||||
|
|
||||||
if (quit)
|
if (quit)
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user