1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-25 01:34:11 +03:00

qemu: Use atomic ops for driver->nactive

This commit is contained in:
Jiri Denemark 2013-02-19 14:57:46 +01:00
parent 921af42980
commit 5d6f636764
2 changed files with 6 additions and 9 deletions

View File

@ -168,7 +168,7 @@ struct _virQEMUDriver {
virCgroupPtr cgroup; virCgroupPtr cgroup;
/* Atomic inc/dec only */ /* Atomic inc/dec only */
size_t nactive; unsigned int nactive;
/* Immutable pointers. Caller must provide locking */ /* Immutable pointers. Caller must provide locking */
virStateInhibitCallback inhibitCallback; virStateInhibitCallback inhibitCallback;

View File

@ -69,6 +69,7 @@
#include "virtime.h" #include "virtime.h"
#include "virnetdevtap.h" #include "virnetdevtap.h"
#include "virbitmap.h" #include "virbitmap.h"
#include "viratomic.h"
#define VIR_FROM_THIS VIR_FROM_QEMU #define VIR_FROM_THIS VIR_FROM_QEMU
@ -3300,9 +3301,8 @@ qemuProcessReconnect(void *opaque)
goto error; goto error;
} }
if (!driver->nactive && driver->inhibitCallback) if (virAtomicIntInc(&driver->nactive) == 1 && driver->inhibitCallback)
driver->inhibitCallback(true, driver->inhibitOpaque); driver->inhibitCallback(true, driver->inhibitOpaque);
driver->nactive++;
endjob: endjob:
if (!qemuDomainObjEndJob(driver, obj)) if (!qemuDomainObjEndJob(driver, obj))
@ -3589,9 +3589,8 @@ int qemuProcessStart(virConnectPtr conn,
qemuDomainSetFakeReboot(driver, vm, false); qemuDomainSetFakeReboot(driver, vm, false);
virDomainObjSetState(vm, VIR_DOMAIN_SHUTOFF, VIR_DOMAIN_SHUTOFF_UNKNOWN); virDomainObjSetState(vm, VIR_DOMAIN_SHUTOFF, VIR_DOMAIN_SHUTOFF_UNKNOWN);
if (!driver->nactive && driver->inhibitCallback) if (virAtomicIntInc(&driver->nactive) == 1 && driver->inhibitCallback)
driver->inhibitCallback(true, driver->inhibitOpaque); driver->inhibitCallback(true, driver->inhibitOpaque);
driver->nactive++;
/* Run an early hook to set-up missing devices */ /* Run an early hook to set-up missing devices */
if (virHookPresent(VIR_HOOK_DRIVER_QEMU)) { if (virHookPresent(VIR_HOOK_DRIVER_QEMU)) {
@ -4188,8 +4187,7 @@ void qemuProcessStop(virQEMUDriverPtr driver,
*/ */
vm->def->id = -1; vm->def->id = -1;
driver->nactive--; if (virAtomicIntDecAndTest(&driver->nactive) && driver->inhibitCallback)
if (!driver->nactive && driver->inhibitCallback)
driver->inhibitCallback(false, driver->inhibitOpaque); driver->inhibitCallback(false, driver->inhibitOpaque);
if ((logfile = qemuDomainCreateLog(driver, vm, true)) < 0) { if ((logfile = qemuDomainCreateLog(driver, vm, true)) < 0) {
@ -4442,9 +4440,8 @@ int qemuProcessAttach(virConnectPtr conn ATTRIBUTE_UNUSED,
vm->def->id = qemuDriverAllocateID(driver); vm->def->id = qemuDriverAllocateID(driver);
if (!driver->nactive && driver->inhibitCallback) if (virAtomicIntInc(&driver->nactive) == 1 && driver->inhibitCallback)
driver->inhibitCallback(true, driver->inhibitOpaque); driver->inhibitCallback(true, driver->inhibitOpaque);
driver->nactive++;
if (virFileMakePath(cfg->logDir) < 0) { if (virFileMakePath(cfg->logDir) < 0) {
virReportSystemError(errno, virReportSystemError(errno,