It already had a virMutex inside, so this is just a cleanup.
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
#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);
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:
if (conn->driver)
conn->driver->connectClose(conn);
- virMutexLock(&conn->lock);
-
virResetError(&conn->err);
virURIFree(conn->uri);
virObjectUnref(conn->closeCallback);
}
-
- virMutexUnlock(&conn->lock);
- virMutexDestroy(&conn->lock);
}
/*
* 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
* 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 */
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 */
/*
* 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
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();
virObjectRef(conn);
- virMutexLock(&conn->lock);
+ virObjectLock(conn);
virObjectLock(conn->closeCallback);
virCheckNonNullArgGoto(cb, error);
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;
virCheckConnectReturn(conn, -1);
- virMutexLock(&conn->lock);
+ virObjectLock(conn);
virObjectLock(conn->closeCallback);
virCheckNonNullArgGoto(cb, error);
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;
}
/*
* 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
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;
}
{
if (conn == NULL)
return;
- virMutexLock(&conn->lock);
+ virObjectLock(conn);
virResetError(&conn->err);
- virMutexUnlock(&conn->lock);
+ virObjectUnlock(conn);
}
/**
{
if (conn == NULL)
return;
- virMutexLock(&conn->lock);
+ virObjectLock(conn);
conn->handler = handler;
conn->userData = userData;
- virMutexUnlock(&conn->lock);
+ virObjectUnlock(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 */