]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
Change virConnectPtr into virObjectLocklable
authorMartin Kletzander <mkletzan@redhat.com>
Thu, 9 Apr 2015 07:43:53 +0000 (09:43 +0200)
committerMartin Kletzander <mkletzan@redhat.com>
Wed, 15 Apr 2015 11:33:35 +0000 (13:33 +0200)
It already had a virMutex inside, so this is just a cleanup.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
src/datatypes.c
src/datatypes.h
src/libvirt-host.c
src/util/virerror.c

index dc024f8398dd913c5f9603b12ba5415fb4d419c7..39f83d94df1a9501267065f93ad87a850b51a135 100644 (file)
@@ -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);
 }
 
 
index 4973b07e185a3f61d18657152d76049156b88e7c..f1d01d5a24c750493c412f9e76a4074e14cd5288 100644 (file)
@@ -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,10 +328,12 @@ struct _virConnectCloseCallbackData {
  * Internal structure associated to a connection
  */
 struct _virConnect {
-    virObject 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
+    virObjectLockable object;
+
+    /* All the variables from here, until declared otherwise in one of
+     * the following comments, are setup at time of connection open
+     * and never changed since. Thus no need to lock when accessing
+     * them.
      */
     unsigned int flags;     /* a set of connection flags */
     virURIPtr uri;          /* connection URI */
@@ -352,12 +354,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 */
index b4dc13e90cb3fabeb69a14653b6cbc67504f80fe..03bee1f5df04ad36fc4a7557174c47766ec37b20 100644 (file)
@@ -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;
 }
index 91c8686399001374792329a2d4fbf052f063eef3..73dae95ec92237effe25b6e3547d50aa55966da3 100644 (file)
@@ -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 */