mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-09 01:18:00 +03:00
datatypes: Use automatic mutex management
Signed-off-by: Tim Wiederhake <twiederh@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
61d51f2d15
commit
8c6e726f7d
@ -217,71 +217,56 @@ void virConnectCloseCallbackDataRegister(virConnectCloseCallbackData *closeData,
|
|||||||
void *opaque,
|
void *opaque,
|
||||||
virFreeCallback freecb)
|
virFreeCallback freecb)
|
||||||
{
|
{
|
||||||
virObjectLock(closeData);
|
VIR_LOCK_GUARD lock = virObjectLockGuard(closeData);
|
||||||
|
|
||||||
if (closeData->callback != NULL) {
|
if (closeData->callback != NULL) {
|
||||||
VIR_WARN("Attempt to register callback on armed"
|
VIR_WARN("Attempt to register callback on armed close callback object %p",
|
||||||
" close callback object %p", closeData);
|
closeData);
|
||||||
goto cleanup;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
closeData->conn = virObjectRef(conn);
|
closeData->conn = virObjectRef(conn);
|
||||||
closeData->callback = cb;
|
closeData->callback = cb;
|
||||||
closeData->opaque = opaque;
|
closeData->opaque = opaque;
|
||||||
closeData->freeCallback = freecb;
|
closeData->freeCallback = freecb;
|
||||||
|
|
||||||
cleanup:
|
|
||||||
|
|
||||||
virObjectUnlock(closeData);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void virConnectCloseCallbackDataUnregister(virConnectCloseCallbackData *closeData,
|
void virConnectCloseCallbackDataUnregister(virConnectCloseCallbackData *closeData,
|
||||||
virConnectCloseFunc cb)
|
virConnectCloseFunc cb)
|
||||||
{
|
{
|
||||||
virObjectLock(closeData);
|
VIR_LOCK_GUARD lock = virObjectLockGuard(closeData);
|
||||||
|
|
||||||
if (closeData->callback != cb) {
|
if (closeData->callback != cb) {
|
||||||
VIR_WARN("Attempt to unregister different callback on "
|
VIR_WARN("Attempt to unregister different callback on close callback object %p",
|
||||||
" close callback object %p", closeData);
|
closeData);
|
||||||
goto cleanup;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
virConnectCloseCallbackDataReset(closeData);
|
virConnectCloseCallbackDataReset(closeData);
|
||||||
closeData->callback = NULL;
|
closeData->callback = NULL;
|
||||||
|
|
||||||
cleanup:
|
|
||||||
|
|
||||||
virObjectUnlock(closeData);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void virConnectCloseCallbackDataCall(virConnectCloseCallbackData *closeData,
|
void virConnectCloseCallbackDataCall(virConnectCloseCallbackData *closeData,
|
||||||
int reason)
|
int reason)
|
||||||
{
|
{
|
||||||
virObjectLock(closeData);
|
VIR_LOCK_GUARD lock = virObjectLockGuard(closeData);
|
||||||
|
|
||||||
if (!closeData->conn)
|
if (!closeData->conn)
|
||||||
goto exit;
|
return;
|
||||||
|
|
||||||
VIR_DEBUG("Triggering connection close callback %p reason=%d, opaque=%p",
|
VIR_DEBUG("Triggering connection close callback %p reason=%d, opaque=%p",
|
||||||
closeData->callback, reason, closeData->opaque);
|
closeData->callback, reason, closeData->opaque);
|
||||||
closeData->callback(closeData->conn, reason, closeData->opaque);
|
closeData->callback(closeData->conn, reason, closeData->opaque);
|
||||||
|
|
||||||
virConnectCloseCallbackDataReset(closeData);
|
virConnectCloseCallbackDataReset(closeData);
|
||||||
|
|
||||||
exit:
|
|
||||||
virObjectUnlock(closeData);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virConnectCloseFunc
|
virConnectCloseFunc
|
||||||
virConnectCloseCallbackDataGetCallback(virConnectCloseCallbackData *closeData)
|
virConnectCloseCallbackDataGetCallback(virConnectCloseCallbackData *closeData)
|
||||||
{
|
{
|
||||||
virConnectCloseFunc cb;
|
VIR_LOCK_GUARD lock = virObjectLockGuard(closeData);
|
||||||
|
|
||||||
virObjectLock(closeData);
|
return closeData->callback;
|
||||||
cb = closeData->callback;
|
|
||||||
virObjectUnlock(closeData);
|
|
||||||
|
|
||||||
return cb;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1128,10 +1113,9 @@ static void
|
|||||||
virAdmConnectCloseCallbackDataDispose(void *obj)
|
virAdmConnectCloseCallbackDataDispose(void *obj)
|
||||||
{
|
{
|
||||||
virAdmConnectCloseCallbackData *cb_data = obj;
|
virAdmConnectCloseCallbackData *cb_data = obj;
|
||||||
|
VIR_LOCK_GUARD lock = virObjectLockGuard(cb_data);
|
||||||
|
|
||||||
virObjectLock(cb_data);
|
|
||||||
virAdmConnectCloseCallbackDataReset(cb_data);
|
virAdmConnectCloseCallbackDataReset(cb_data);
|
||||||
virObjectUnlock(cb_data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -1150,20 +1134,16 @@ int
|
|||||||
virAdmConnectCloseCallbackDataUnregister(virAdmConnectCloseCallbackData *cbdata,
|
virAdmConnectCloseCallbackDataUnregister(virAdmConnectCloseCallbackData *cbdata,
|
||||||
virAdmConnectCloseFunc cb)
|
virAdmConnectCloseFunc cb)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
VIR_LOCK_GUARD lock = virObjectLockGuard(cbdata);
|
||||||
|
|
||||||
virObjectLock(cbdata);
|
|
||||||
if (cbdata->callback != cb) {
|
if (cbdata->callback != cb) {
|
||||||
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
||||||
_("A different callback was requested"));
|
_("A different callback was requested"));
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
virAdmConnectCloseCallbackDataReset(cbdata);
|
virAdmConnectCloseCallbackDataReset(cbdata);
|
||||||
ret = 0;
|
return 0;
|
||||||
cleanup:
|
|
||||||
virObjectUnlock(cbdata);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -1173,14 +1153,12 @@ virAdmConnectCloseCallbackDataRegister(virAdmConnectCloseCallbackData *cbdata,
|
|||||||
void *opaque,
|
void *opaque,
|
||||||
virFreeCallback freecb)
|
virFreeCallback freecb)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
VIR_LOCK_GUARD lock = virObjectLockGuard(cbdata);
|
||||||
|
|
||||||
virObjectLock(cbdata);
|
|
||||||
|
|
||||||
if (cbdata->callback) {
|
if (cbdata->callback) {
|
||||||
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
||||||
_("A close callback is already registered"));
|
_("A close callback is already registered"));
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
cbdata->conn = virObjectRef(conn);
|
cbdata->conn = virObjectRef(conn);
|
||||||
@ -1188,10 +1166,7 @@ virAdmConnectCloseCallbackDataRegister(virAdmConnectCloseCallbackData *cbdata,
|
|||||||
cbdata->opaque = opaque;
|
cbdata->opaque = opaque;
|
||||||
cbdata->freeCallback = freecb;
|
cbdata->freeCallback = freecb;
|
||||||
|
|
||||||
ret = 0;
|
return 0;
|
||||||
cleanup:
|
|
||||||
virObjectUnlock(conn->closeCallback);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virAdmServerPtr
|
virAdmServerPtr
|
||||||
|
Loading…
Reference in New Issue
Block a user