[PATCH 37/43] tools: virsh: convert virMutex to GMutex

Rafael Fonseca r4f4rfs at gmail.com
Fri Apr 10 13:55:04 UTC 2020


Signed-off-by: Rafael Fonseca <r4f4rfs at gmail.com>
---
 tools/virsh.c      | 11 ++++-------
 tools/virt-admin.c | 11 ++++-------
 tools/vsh.c        |  4 ++--
 tools/vsh.h        |  2 +-
 4 files changed, 11 insertions(+), 17 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index 197a90636d..f2da8ad340 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -414,11 +414,11 @@ virshDeinit(vshControl *ctl)
     if (ctl->eventLoopStarted) {
         int timer;
 
-        virMutexLock(&ctl->lock);
+        g_mutex_lock(&ctl->lock);
         ctl->quit = true;
         /* HACK: Add a dummy timeout to break event loop */
         timer = virEventAddTimeout(0, virshDeinitTimer, NULL, NULL);
-        virMutexUnlock(&ctl->lock);
+        g_mutex_unlock(&ctl->lock);
 
         virThreadJoin(&ctl->eventLoop);
 
@@ -431,7 +431,7 @@ virshDeinit(vshControl *ctl)
         ctl->eventLoopStarted = false;
     }
 
-    virMutexDestroy(&ctl->lock);
+    g_mutex_clear(&ctl->lock);
 
     return true;
 }
@@ -877,10 +877,7 @@ main(int argc, char **argv)
 #endif
     }
 
-    if (virMutexInit(&ctl->lock) < 0) {
-        vshError(ctl, "%s", _("Failed to initialize mutex"));
-        return EXIT_FAILURE;
-    }
+    g_mutex_init(&ctl->lock);
 
     if (virInitialize() < 0) {
         vshError(ctl, "%s", _("Failed to initialize libvirt"));
diff --git a/tools/virt-admin.c b/tools/virt-admin.c
index a8e5e0a5af..712bac07df 100644
--- a/tools/virt-admin.c
+++ b/tools/virt-admin.c
@@ -1203,11 +1203,11 @@ vshAdmDeinit(vshControl *ctl)
     if (ctl->eventLoopStarted) {
         int timer;
 
-        virMutexLock(&ctl->lock);
+        g_mutex_lock(&ctl->lock);
         ctl->quit = true;
         /* HACK: Add a dummy timeout to break event loop */
         timer = virEventAddTimeout(0, vshAdmDeinitTimer, NULL, NULL);
-        virMutexUnlock(&ctl->lock);
+        g_mutex_unlock(&ctl->lock);
 
         virThreadJoin(&ctl->eventLoop);
 
@@ -1217,7 +1217,7 @@ vshAdmDeinit(vshControl *ctl)
         ctl->eventLoopStarted = false;
     }
 
-    virMutexDestroy(&ctl->lock);
+    g_mutex_clear(&ctl->lock);
 }
 
 /*
@@ -1563,10 +1563,7 @@ main(int argc, char **argv)
 #endif
     }
 
-    if (virMutexInit(&ctl->lock) < 0) {
-        vshError(ctl, "%s", _("Failed to initialize mutex"));
-        return EXIT_FAILURE;
-    }
+    g_mutex_init(&ctl->lock);
 
     if (virAdmInitialize() < 0) {
         vshError(ctl, "%s", _("Failed to initialize libvirt"));
diff --git a/tools/vsh.c b/tools/vsh.c
index 58bb1e6a3c..b803dd6aa5 100644
--- a/tools/vsh.c
+++ b/tools/vsh.c
@@ -1989,9 +1989,9 @@ vshEventLoop(void *opaque)
 
     while (1) {
         bool quit;
-        virMutexLock(&ctl->lock);
+        g_mutex_lock(&ctl->lock);
         quit = ctl->quit;
-        virMutexUnlock(&ctl->lock);
+        g_mutex_unlock(&ctl->lock);
 
         if (quit)
             break;
diff --git a/tools/vsh.h b/tools/vsh.h
index 174116b369..49e1fef06e 100644
--- a/tools/vsh.h
+++ b/tools/vsh.h
@@ -208,7 +208,7 @@ struct _vshControl {
     char *historydir;           /* readline history directory name */
     char *historyfile;          /* readline history file name */
     virThread eventLoop;
-    virMutex lock;
+    GMutex lock;
     bool eventLoopStarted;
     bool quit;
     int eventPipe[2];           /* Write-to-self pipe to end waiting for an
-- 
2.25.2





More information about the libvir-list mailing list