Add a g->lock field. This commit simply initializes and destroys the
lock on handle creation/free, and does nothing else.
---
src/guestfs-internal.h | 6 ++++++
src/handle.c | 4 ++++
2 files changed, 10 insertions(+)
diff --git a/src/guestfs-internal.h b/src/guestfs-internal.h
index bbd7fb4..b68942f 100644
--- a/src/guestfs-internal.h
+++ b/src/guestfs-internal.h
@@ -33,6 +33,7 @@
#include <libvirt/libvirt.h>
#endif
+#include "glthread/lock.h"
#include "hash.h"
#include "guestfs-internal-frontend.h"
@@ -365,6 +366,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
+ * protects the handle.
+ */
+ gl_recursive_lock_define (, lock);
+
/**** Configuration of the handle. ****/
bool verbose; /* Debugging. */
bool trace; /* Trace calls. */
diff --git a/src/handle.c b/src/handle.c
index 51b9572..a057475 100644
--- a/src/handle.c
+++ b/src/handle.c
@@ -84,6 +84,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;
@@ -167,6 +169,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;
}
@@ -389,6 +392,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.3.1