[PATCH 4/5] Change virConnectPtr into virObjectLocklable

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

 



It already had a virMutex inside, so this is just a cleanup.

Signed-off-by: Martin Kletzander <mkletzan@xxxxxxxxxx>
---
 src/datatypes.c     | 12 ++----------
 src/datatypes.h     | 12 +++++-------
 src/libvirt-host.c  | 18 +++++++++---------
 src/util/virerror.c | 18 +++++++++---------
 4 files changed, 25 insertions(+), 35 deletions(-)

diff --git a/src/datatypes.c b/src/datatypes.c
index dc024f8..39f83d9 100644
--- a/src/datatypes.c
+++ b/src/datatypes.c
@@ -73,7 +73,7 @@ virDataTypesOnceInit(void)
 #define DECLARE_CLASS_LOCKABLE(basename)                         \
     DECLARE_CLASS_COMMON(basename, virClassForObjectLockable())

-    DECLARE_CLASS(virConnect);
+    DECLARE_CLASS_LOCKABLE(virConnect);
     DECLARE_CLASS_LOCKABLE(virConnectCloseCallbackData);
     DECLARE_CLASS(virDomain);
     DECLARE_CLASS(virDomainSnapshot);
@@ -110,15 +110,12 @@ virGetConnect(void)
     if (virDataTypesInitialize() < 0)
         return NULL;

-    if (!(ret = virObjectNew(virConnectClass)))
+    if (!(ret = virObjectLockableNew(virConnectClass)))
         return NULL;

     if (!(ret->closeCallback = virObjectLockableNew(virConnectCloseCallbackDataClass)))
         goto error;

-    if (virMutexInit(&ret->lock) < 0)
-        goto error;
-
     return ret;

  error:
@@ -141,8 +138,6 @@ virConnectDispose(void *obj)
     if (conn->driver)
         conn->driver->connectClose(conn);

-    virMutexLock(&conn->lock);
-
     virResetError(&conn->err);

     virURIFree(conn->uri);
@@ -154,9 +149,6 @@ virConnectDispose(void *obj)

         virObjectUnref(conn->closeCallback);
     }
-
-    virMutexUnlock(&conn->lock);
-    virMutexDestroy(&conn->lock);
 }


diff --git a/src/datatypes.h b/src/datatypes.h
index 4973b07..9e19c55 100644
--- a/src/datatypes.h
+++ b/src/datatypes.h
@@ -1,7 +1,7 @@
 /*
  * datatypes.h: management of structs for public data types
  *
- * Copyright (C) 2006-2014 Red Hat, Inc.
+ * Copyright (C) 2006-2015 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -328,7 +328,7 @@ struct _virConnectCloseCallbackData {
  * Internal structure associated to a connection
  */
 struct _virConnect {
-    virObject object;
+    virObjectLockable object;
     /* All the variables from here, until the 'lock' declaration
      * are setup at time of connection open, and never changed
      * since. Thus no need to lock when accessing them
@@ -352,12 +352,10 @@ struct _virConnect {
     void *            privateData;

     /*
-     * The lock mutex must be acquired before accessing/changing
-     * any of members following this point, or changing the ref
-     * count of any virDomain/virNetwork object associated with
-     * this connection
+     * Object lock must be acquired before accessing/changing any of
+     * members following this point, or changing the ref count of any
+     * virDomain/virNetwork object associated with this connection.
      */
-    virMutex lock;

     /* Per-connection error. */
     virError err;           /* the last error */
diff --git a/src/libvirt-host.c b/src/libvirt-host.c
index b4dc13e..03bee1f 100644
--- a/src/libvirt-host.c
+++ b/src/libvirt-host.c
@@ -1,7 +1,7 @@
 /*
  * libvirt-host.c: entry points for vir{Connect,Node}Ptr APIs
  *
- * Copyright (C) 2006-2014 Red Hat, Inc.
+ * Copyright (C) 2006-2015 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -51,7 +51,7 @@ VIR_LOG_INIT("libvirt.host");
 int
 virConnectRef(virConnectPtr conn)
 {
-    VIR_DEBUG("conn=%p refs=%d", conn, conn ? conn->object.u.s.refs : 0);
+    VIR_DEBUG("conn=%p refs=%d", conn, conn ? conn->object.parent.u.s.refs : 0);

     virResetLastError();

@@ -1219,7 +1219,7 @@ virConnectRegisterCloseCallback(virConnectPtr conn,

     virObjectRef(conn);

-    virMutexLock(&conn->lock);
+    virObjectLock(conn);
     virObjectLock(conn->closeCallback);

     virCheckNonNullArgGoto(cb, error);
@@ -1236,13 +1236,13 @@ virConnectRegisterCloseCallback(virConnectPtr conn,
     conn->closeCallback->freeCallback = freecb;

     virObjectUnlock(conn->closeCallback);
-    virMutexUnlock(&conn->lock);
+    virObjectUnlock(conn);

     return 0;

  error:
     virObjectUnlock(conn->closeCallback);
-    virMutexUnlock(&conn->lock);
+    virObjectUnlock(conn);
     virDispatchError(conn);
     virObjectUnref(conn);
     return -1;
@@ -1272,7 +1272,7 @@ virConnectUnregisterCloseCallback(virConnectPtr conn,

     virCheckConnectReturn(conn, -1);

-    virMutexLock(&conn->lock);
+    virObjectLock(conn);
     virObjectLock(conn->closeCallback);

     virCheckNonNullArgGoto(cb, error);
@@ -1288,15 +1288,15 @@ virConnectUnregisterCloseCallback(virConnectPtr conn,
         conn->closeCallback->freeCallback(conn->closeCallback->opaque);
     conn->closeCallback->freeCallback = NULL;

-    virObjectUnref(conn);
     virObjectUnlock(conn->closeCallback);
-    virMutexUnlock(&conn->lock);
+    virObjectUnlock(conn);
+    virObjectUnref(conn);

     return 0;

  error:
     virObjectUnlock(conn->closeCallback);
-    virMutexUnlock(&conn->lock);
+    virObjectUnlock(conn);
     virDispatchError(conn);
     return -1;
 }
diff --git a/src/util/virerror.c b/src/util/virerror.c
index c4e84e7..942fe35 100644
--- a/src/util/virerror.c
+++ b/src/util/virerror.c
@@ -1,7 +1,7 @@
 /*
  * virerror.c: error handling and reporting code for libvirt
  *
- * Copyright (C) 2006, 2008-2014 Red Hat, Inc.
+ * Copyright (C) 2006, 2008-2015 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -460,12 +460,12 @@ virConnCopyLastError(virConnectPtr conn, virErrorPtr to)

     if (conn == NULL)
         return -1;
-    virMutexLock(&conn->lock);
+    virObjectLock(conn);
     if (conn->err.code == VIR_ERR_OK)
         virResetError(to);
     else
         virCopyError(&conn->err, to);
-    virMutexUnlock(&conn->lock);
+    virObjectUnlock(conn);
     return to->code;
 }

@@ -483,9 +483,9 @@ virConnResetLastError(virConnectPtr conn)
 {
     if (conn == NULL)
         return;
-    virMutexLock(&conn->lock);
+    virObjectLock(conn);
     virResetError(&conn->err);
-    virMutexUnlock(&conn->lock);
+    virObjectUnlock(conn);
 }

 /**
@@ -520,10 +520,10 @@ virConnSetErrorFunc(virConnectPtr conn, void *userData,
 {
     if (conn == NULL)
         return;
-    virMutexLock(&conn->lock);
+    virObjectLock(conn);
     conn->handler = handler;
     conn->userData = userData;
-    virMutexUnlock(&conn->lock);
+    virObjectUnlock(conn);
 }

 /**
@@ -600,14 +600,14 @@ virDispatchError(virConnectPtr conn)

     /* Copy the global error to per-connection error if needed */
     if (conn) {
-        virMutexLock(&conn->lock);
+        virObjectLock(conn);
         virCopyError(err, &conn->err);

         if (conn->handler != NULL) {
             handler = conn->handler;
             userData = conn->userData;
         }
-        virMutexUnlock(&conn->lock);
+        virObjectUnlock(conn);
     }

     /* Invoke the error callback functions */
-- 
2.3.5

--
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]