[libvirt PATCH 03/11] libxl: Use automatic memory management

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

 



Signed-off-by: Tim Wiederhake <twiederh@xxxxxxxxxx>
---
 src/libxl/libxl_conf.c   |  8 ++------
 src/libxl/libxl_conf.h   | 12 ------------
 src/libxl/libxl_logger.c | 20 +++++++++-----------
 3 files changed, 11 insertions(+), 29 deletions(-)

diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
index f062f8e958..a0fc51c74a 100644
--- a/src/libxl/libxl_conf.c
+++ b/src/libxl/libxl_conf.c
@@ -1815,12 +1815,8 @@ libxlDriverConfigInit(libxlDriverConfig *cfg)
 libxlDriverConfig *
 libxlDriverConfigGet(libxlDriverPrivate *driver)
 {
-    libxlDriverConfig *cfg;
-
-    libxlDriverLock(driver);
-    cfg = virObjectRef(driver->config);
-    libxlDriverUnlock(driver);
-    return cfg;
+    VIR_LOCK_GUARD lock = virLockGuardLock(&driver->lock);
+    return virObjectRef(driver->config);
 }
 
 int libxlDriverConfigLoadFile(libxlDriverConfig *cfg,
diff --git a/src/libxl/libxl_conf.h b/src/libxl/libxl_conf.h
index b74f455b69..16a7195bfd 100644
--- a/src/libxl/libxl_conf.h
+++ b/src/libxl/libxl_conf.h
@@ -219,15 +219,3 @@ libxlBuildDomainConfig(virPortAllocatorRange *graphicsports,
                        virDomainDef *def,
                        libxlDriverConfig *cfg,
                        libxl_domain_config *d_config);
-
-static inline void
-libxlDriverLock(libxlDriverPrivate *driver)
-{
-    virMutexLock(&driver->lock);
-}
-
-static inline void
-libxlDriverUnlock(libxlDriverPrivate *driver)
-{
-    virMutexUnlock(&driver->lock);
-}
diff --git a/src/libxl/libxl_logger.c b/src/libxl/libxl_logger.c
index 4708553f29..45cdc32f38 100644
--- a/src/libxl/libxl_logger.c
+++ b/src/libxl/libxl_logger.c
@@ -79,16 +79,16 @@ libvirt_vmessage(xentoollog_logger *logger_in,
     /* Should we print to a domain-specific log file? */
     if ((start = strstr(message, ": Domain ")) &&
         (end = strstr(start + 9, ":"))) {
-        FILE *domainLogFile;
+        FILE *domainLogFile = NULL;
 
         VIR_DEBUG("Found domain log message");
 
         start = start + 9;
         *end = '\0';
 
-        virMutexLock(&lg->tableLock);
-        domainLogFile = virHashLookup(lg->files, start);
-        virMutexUnlock(&lg->tableLock);
+        VIR_WITH_MUTEX_LOCK_GUARD(&lg->tableLock) {
+            domainLogFile = virHashLookup(lg->files, start);
+        }
         if (domainLogFile)
             logFile = domainLogFile;
 
@@ -197,9 +197,9 @@ libxlLoggerOpenFile(libxlLogger *logger,
                  path, g_strerror(errno));
         return;
     }
-    virMutexLock(&logger->tableLock);
-    ignore_value(virHashAddEntry(logger->files, domidstr, logFile));
-    virMutexUnlock(&logger->tableLock);
+    VIR_WITH_MUTEX_LOCK_GUARD(&logger->tableLock) {
+        ignore_value(virHashAddEntry(logger->files, domidstr, logFile));
+    }
 
     /* domain_config is non NULL only when starting a new domain */
     if (domain_config) {
@@ -211,10 +211,8 @@ libxlLoggerOpenFile(libxlLogger *logger,
 void
 libxlLoggerCloseFile(libxlLogger *logger, int id)
 {
-    g_autofree char *domidstr = NULL;
-    domidstr = g_strdup_printf("%d", id);
+    g_autofree char *domidstr = g_strdup_printf("%d", id);
+    VIR_LOCK_GUARD lock = virLockGuardLock(&logger->tableLock);
 
-    virMutexLock(&logger->tableLock);
     ignore_value(virHashRemoveEntry(logger->files, domidstr));
-    virMutexUnlock(&logger->tableLock);
 }
-- 
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