Add a g->lock field.  This commit simply initializes and destroys the
lock on handle creation/free, and does nothing else.
---
 lib/guestfs-internal.h | 6 ++++++
 lib/handle.c           | 4 ++++
 2 files changed, 10 insertions(+)

diff --git a/lib/guestfs-internal.h b/lib/guestfs-internal.h
index 7269fbeba..10080c4b7 100644
--- a/lib/guestfs-internal.h
+++ b/lib/guestfs-internal.h
@@ -52,6 +52,7 @@
 #endif
 #endif
 
+#include "glthread/lock.h"
 #include "hash.h"
 
 #include "guestfs-utils.h"
@@ -388,6 +389,11 @@ struct guestfs_h {
   struct guestfs_h *next;      /* Linked list of open handles. */
   enum state state;             /* See the state machine diagram in 
guestfs(3)*/
 
+  /* Lock acquired when entering any public guestfs_* function to
+   * protect the handle.
+   */
+  gl_recursive_lock_define (, lock);
+
   /**** Configuration of the handle. ****/
   bool verbose;                 /* Debugging. */
   bool trace;                   /* Trace calls. */
diff --git a/lib/handle.c b/lib/handle.c
index 91f5f755d..09c29ed84 100644
--- a/lib/handle.c
+++ b/lib/handle.c
@@ -86,6 +86,8 @@ guestfs_create_flags (unsigned flags, ...)
   g = calloc (1, sizeof (*g));
   if (!g) return NULL;
 
+  gl_recursive_lock_init (g->lock);
+
   g->state = CONFIG;
 
   g->conn = NULL;
@@ -169,6 +171,7 @@ guestfs_create_flags (unsigned flags, ...)
   free (g->path);
   free (g->hv);
   free (g->append);
+  gl_recursive_lock_destroy (g->lock);
   free (g);
   return NULL;
 }
@@ -399,6 +402,7 @@ guestfs_close (guestfs_h *g)
   free (g->backend_data);
   guestfs_int_free_string_list (g->backend_settings);
   free (g->append);
+  gl_recursive_lock_destroy (g->lock);
   free (g);
 }
 
-- 
2.13.2

_______________________________________________
Libguestfs mailing list
Libguestfs@redhat.com
https://www.redhat.com/mailman/listinfo/libguestfs

Reply via email to