[libvirt PATCH v2 05/13] nwfilter_dhcpsnoop: Replace virNWFilterSnoopActiveLock macros

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

 



Use automatic mutex management instead.

Signed-off-by: Tim Wiederhake <twiederh@xxxxxxxxxx>
---
 src/nwfilter/nwfilter_dhcpsnoop.c | 42 ++++++++-----------------------
 1 file changed, 11 insertions(+), 31 deletions(-)

diff --git a/src/nwfilter/nwfilter_dhcpsnoop.c b/src/nwfilter/nwfilter_dhcpsnoop.c
index f8cffc7d57..c526653bc2 100644
--- a/src/nwfilter/nwfilter_dhcpsnoop.c
+++ b/src/nwfilter/nwfilter_dhcpsnoop.c
@@ -93,14 +93,6 @@ struct virNWFilterSnoopState {
     do { \
         virMutexUnlock(&virNWFilterSnoopState.snoopLock); \
     } while (0)
-# define virNWFilterSnoopActiveLock() \
-    do { \
-        virMutexLock(&virNWFilterSnoopState.activeLock); \
-    } while (0)
-# define virNWFilterSnoopActiveUnlock() \
-    do { \
-        virMutexUnlock(&virNWFilterSnoopState.activeLock); \
-    } while (0)
 
 # define VIR_IFKEY_LEN   ((VIR_UUID_STRING_BUFLEN) + (VIR_MAC_STRING_BUFLEN))
 
@@ -281,47 +273,35 @@ static char *
 virNWFilterSnoopActivate(virNWFilterSnoopReq *req)
 {
     g_autofree char *key = g_strdup_printf("%p-%d", req, req->ifindex);
-    char *ret = NULL;
+    VIR_LOCK_GUARD lock = virLockGuardLock(&virNWFilterSnoopState.activeLock);
 
-    virNWFilterSnoopActiveLock();
-
-    if (virHashAddEntry(virNWFilterSnoopState.active, key, (void *)0x1) == 0)
-        ret = g_steal_pointer(&key);
-
-    virNWFilterSnoopActiveUnlock();
+    if (virHashAddEntry(virNWFilterSnoopState.active, key, (void *)0x1) < 0)
+        return NULL;
 
-    return ret;
+    return g_steal_pointer(&key);
 }
 
 static void
 virNWFilterSnoopCancel(char **threadKey)
 {
+    VIR_LOCK_GUARD lock = virLockGuardLock(&virNWFilterSnoopState.activeLock);
+
     if (*threadKey == NULL)
         return;
 
-    virNWFilterSnoopActiveLock();
-
     ignore_value(virHashRemoveEntry(virNWFilterSnoopState.active, *threadKey));
     g_clear_pointer(threadKey, g_free);
-
-    virNWFilterSnoopActiveUnlock();
 }
 
 static bool
 virNWFilterSnoopIsActive(char *threadKey)
 {
-    void *entry;
+    VIR_LOCK_GUARD lock = virLockGuardLock(&virNWFilterSnoopState.activeLock);
 
     if (threadKey == NULL)
         return false;
 
-    virNWFilterSnoopActiveLock();
-
-    entry = virHashLookup(virNWFilterSnoopState.active, threadKey);
-
-    virNWFilterSnoopActiveUnlock();
-
-    return entry != NULL;
+    return virHashLookup(virNWFilterSnoopState.active, threadKey) != NULL;
 }
 
 /*
@@ -2083,9 +2063,9 @@ virNWFilterDHCPSnoopShutdown(void)
 
     virNWFilterSnoopUnlock();
 
-    virNWFilterSnoopActiveLock();
-    g_clear_pointer(&virNWFilterSnoopState.active, g_hash_table_unref);
-    virNWFilterSnoopActiveUnlock();
+    VIR_WITH_MUTEX_LOCK_GUARD(&virNWFilterSnoopState.activeLock) {
+        g_clear_pointer(&virNWFilterSnoopState.active, g_hash_table_unref);
+    }
 }
 
 #else /* WITH_LIBPCAP */
-- 
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