Change virConnectPtr into virObjectLocklable

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

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
This commit is contained in:
Martin Kletzander 2015-04-09 09:43:53 +02:00
parent 6dfbaca7b7
commit fae5b555c8
4 changed files with 30 additions and 38 deletions

View 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);
}

View 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 */

View 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;
}

View 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 */