[libvirt PATCH 08/10] datatypes: Use automatic mutex management

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

 



Signed-off-by: Tim Wiederhake <twiederh@xxxxxxxxxx>
---
 src/datatypes.c | 63 +++++++++++++++----------------------------------
 1 file changed, 19 insertions(+), 44 deletions(-)

diff --git a/src/datatypes.c b/src/datatypes.c
index aa614612f9..da8a9970f1 100644
--- a/src/datatypes.c
+++ b/src/datatypes.c
@@ -217,71 +217,56 @@ void virConnectCloseCallbackDataRegister(virConnectCloseCallbackData *closeData,
                                          void *opaque,
                                          virFreeCallback freecb)
 {
-    virObjectLock(closeData);
+    VIR_LOCK_GUARD lock = virObjectLockGuard(closeData);
 
     if (closeData->callback != NULL) {
-        VIR_WARN("Attempt to register callback on armed"
-                 " close callback object %p", closeData);
-        goto cleanup;
+        VIR_WARN("Attempt to register callback on armed close callback object %p",
+                 closeData);
+        return;
     }
 
     closeData->conn = virObjectRef(conn);
     closeData->callback = cb;
     closeData->opaque = opaque;
     closeData->freeCallback = freecb;
-
- cleanup:
-
-    virObjectUnlock(closeData);
 }
 
 void virConnectCloseCallbackDataUnregister(virConnectCloseCallbackData *closeData,
                                            virConnectCloseFunc cb)
 {
-    virObjectLock(closeData);
+    VIR_LOCK_GUARD lock = virObjectLockGuard(closeData);
 
     if (closeData->callback != cb) {
-        VIR_WARN("Attempt to unregister different callback on "
-                 " close callback object %p", closeData);
-        goto cleanup;
+        VIR_WARN("Attempt to unregister different callback on  close callback object %p",
+                 closeData);
+        return;
     }
 
     virConnectCloseCallbackDataReset(closeData);
     closeData->callback = NULL;
-
- cleanup:
-
-    virObjectUnlock(closeData);
 }
 
 void virConnectCloseCallbackDataCall(virConnectCloseCallbackData *closeData,
                                      int reason)
 {
-    virObjectLock(closeData);
+    VIR_LOCK_GUARD lock = virObjectLockGuard(closeData);
 
     if (!closeData->conn)
-        goto exit;
+        return;
 
     VIR_DEBUG("Triggering connection close callback %p reason=%d, opaque=%p",
               closeData->callback, reason, closeData->opaque);
     closeData->callback(closeData->conn, reason, closeData->opaque);
 
     virConnectCloseCallbackDataReset(closeData);
-
- exit:
-    virObjectUnlock(closeData);
 }
 
 virConnectCloseFunc
 virConnectCloseCallbackDataGetCallback(virConnectCloseCallbackData *closeData)
 {
-    virConnectCloseFunc cb;
-
-    virObjectLock(closeData);
-    cb = closeData->callback;
-    virObjectUnlock(closeData);
+    VIR_LOCK_GUARD lock = virObjectLockGuard(closeData);
 
-    return cb;
+    return closeData->callback;
 }
 
 /**
@@ -1128,10 +1113,9 @@ static void
 virAdmConnectCloseCallbackDataDispose(void *obj)
 {
     virAdmConnectCloseCallbackData *cb_data = obj;
+    VIR_LOCK_GUARD lock = virObjectLockGuard(cb_data);
 
-    virObjectLock(cb_data);
     virAdmConnectCloseCallbackDataReset(cb_data);
-    virObjectUnlock(cb_data);
 }
 
 void
@@ -1150,20 +1134,16 @@ int
 virAdmConnectCloseCallbackDataUnregister(virAdmConnectCloseCallbackData *cbdata,
                                          virAdmConnectCloseFunc cb)
 {
-    int ret = -1;
+    VIR_LOCK_GUARD lock = virObjectLockGuard(cbdata);
 
-    virObjectLock(cbdata);
     if (cbdata->callback != cb) {
         virReportError(VIR_ERR_OPERATION_INVALID, "%s",
                        _("A different callback was requested"));
-        goto cleanup;
+        return -1;
     }
 
     virAdmConnectCloseCallbackDataReset(cbdata);
-    ret = 0;
- cleanup:
-    virObjectUnlock(cbdata);
-    return ret;
+    return 0;
 }
 
 int
@@ -1173,14 +1153,12 @@ virAdmConnectCloseCallbackDataRegister(virAdmConnectCloseCallbackData *cbdata,
                                        void *opaque,
                                        virFreeCallback freecb)
 {
-    int ret = -1;
-
-    virObjectLock(cbdata);
+    VIR_LOCK_GUARD lock = virObjectLockGuard(cbdata);
 
     if (cbdata->callback) {
         virReportError(VIR_ERR_OPERATION_INVALID, "%s",
                        _("A close callback is already registered"));
-        goto cleanup;
+        return -1;
     }
 
     cbdata->conn = virObjectRef(conn);
@@ -1188,10 +1166,7 @@ virAdmConnectCloseCallbackDataRegister(virAdmConnectCloseCallbackData *cbdata,
     cbdata->opaque = opaque;
     cbdata->freeCallback = freecb;
 
-    ret = 0;
- cleanup:
-    virObjectUnlock(conn->closeCallback);
-    return ret;
+    return 0;
 }
 
 virAdmServerPtr
-- 
2.31.1




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

  Powered by Linux