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;
err = firewall->err;
virReportSystemError(err, "%s", _("Unable to create rule"));
- goto cleanup;
+ return -1;
}
VIR_DEBUG("Applying groups for %p", 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;
}
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);
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);
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;