X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=src%2Fguestfs.c;h=7cc09cead39a5fb4fc83cfc7dc2f96fb6fdbd441;hb=5c6147ecc7ee3cf657edb1e19ad5ab4e973424e0;hp=41872d36758b1ecd0aa8a87f5ea39b22d30a394b;hpb=da33feca279d8feea3cd4b290c0d62c011f30d61;p=libguestfs.git diff --git a/src/guestfs.c b/src/guestfs.c index 41872d3..7cc09ce 100644 --- a/src/guestfs.c +++ b/src/guestfs.c @@ -60,11 +60,14 @@ #include #include +#include "c-ctype.h" +#include "glthread/lock.h" +#include "ignore-value.h" + #include "guestfs.h" +#include "guestfs-internal.h" #include "guestfs-internal-actions.h" #include "guestfs_protocol.h" -#include "c-ctype.h" -#include "ignore-value.h" #ifdef HAVE_GETTEXT #include "gettext.h" @@ -149,6 +152,7 @@ struct guestfs_h int msg_next_serial; }; +gl_lock_define_initialized (static, handles_lock); static guestfs_h *handles = NULL; static int atexit_handler_set = 0; @@ -216,17 +220,15 @@ guestfs_create (void) */ g->msg_next_serial = 0x00123400; - /* Link the handles onto a global list. This is the one area - * where the library needs to be made thread-safe. (XXX) - */ - /* acquire mutex (XXX) */ + /* Link the handles onto a global list. */ + gl_lock_lock (handles_lock); g->next = handles; handles = g; if (!atexit_handler_set) { atexit (close_handles); atexit_handler_set = 1; } - /* release mutex (XXX) */ + gl_lock_unlock (handles_lock); if (g->verbose) fprintf (stderr, "new guestfs handle %p\n", g); @@ -311,7 +313,7 @@ guestfs_close (guestfs_h *g) /* Mark the handle as dead before freeing it. */ g->state = NO_HANDLE; - /* acquire mutex (XXX) */ + gl_lock_lock (handles_lock); if (handles == g) handles = g->next; else { @@ -319,7 +321,7 @@ guestfs_close (guestfs_h *g) ; gg->next = g->next; } - /* release mutex (XXX) */ + gl_lock_unlock (handles_lock); free (g->last_error); free (g->path); @@ -1539,7 +1541,7 @@ print_timestamped_message (guestfs_h *g, const char *fs, ...) if (err < 0) return; gettimeofday (&tv, NULL); - + fprintf (stderr, "[%05" PRIi64 "ms] %s\n", timeval_diff (&g->launch_t, &tv), msg);