[PATCH v2 08/15] test: Use atomic access to @nextDomID in struct virTestDriver

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 src/test/test_driver.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 0cd8e6a..1d54639 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -59,6 +59,7 @@
 #include "virstring.h"
 #include "cpu/cpu.h"
 #include "virauth.h"
+#include "viratomic.h"

 #define VIR_FROM_THIS VIR_FROM_TEST

@@ -95,7 +96,6 @@ typedef struct _testAuth *testAuthPtr;
 struct _testDriver {
     virMutex lock;

-    int nextDomID;
     virNodeInfo nodeInfo;
     virInterfaceObjList ifaces;
     bool transaction_running;
@@ -107,6 +107,9 @@ struct _testDriver {
     size_t numAuths;
     testAuthPtr auths;

+    /* virAtomic access only */
+    volatile int nextDomID;
+
     /* immutable pointer, immutable object after being initialized with
      * testBuildCapabilities */
     virCapsPtr caps;
@@ -417,7 +420,7 @@ testDriverNew(void)
         !(ret->networks = virNetworkObjListNew()))
         goto error;

-    ret->nextDomID = 1;
+    virAtomicIntSet(&ret->nextDomID, 1);

     return ret;

@@ -712,7 +715,7 @@ testDomainStartState(testDriverPtr privconn,
         goto cleanup;

     virDomainObjSetState(dom, VIR_DOMAIN_RUNNING, reason);
-    dom->def->id = privconn->nextDomID++;
+    dom->def->id = virAtomicIntAdd(&privconn->nextDomID, 1);

     if (virDomainObjSetDefTransient(privconn->caps,
                                     privconn->xmlopt,
-- 
2.4.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]