This commit uses the Gnulib 'lock' module to implement a mutex on
the global list of handles which is stored by the library.
Note that Gnulib nicely avoids explicitly linking with -lpthread
unless the application program itself links to -lpthread. Locks
are only enabled in multithreaded applications.
$ ldd src/.libs/libguestfs.so.0.217.0
linux-vdso.so.1 => (0x00007fffcb7ff000)
libc.so.6 => /lib64/libc.so.6 (0x00007f96a4e6c000)
/lib64/ld-linux-x86-64.so.2 (0x00007f96a544d000)
Please enter the commit message for your changes. Lines starting
hash
hash-pjw
ignore-value
hash
hash-pjw
ignore-value
maintainer-makefile
manywarnings
netinet_in
maintainer-makefile
manywarnings
netinet_in
/hash.m4
/inttostr.m4
/putenv.m4
/hash.m4
/inttostr.m4
/putenv.m4
#include <arpa/inet.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netinet/in.h>
+#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 "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"
#ifdef HAVE_GETTEXT
#include "gettext.h"
+gl_lock_define_initialized (static, handles_lock);
static guestfs_h *handles = NULL;
static int atexit_handler_set = 0;
static guestfs_h *handles = NULL;
static int atexit_handler_set = 0;
*/
g->msg_next_serial = 0x00123400;
*/
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;
}
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);
if (g->verbose)
fprintf (stderr, "new guestfs handle %p\n", g);
/* Mark the handle as dead before freeing it. */
g->state = NO_HANDLE;
/* 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 {
if (handles == g)
handles = g->next;
else {
- /* release mutex (XXX) */
+ gl_lock_unlock (handles_lock);
free (g->last_error);
free (g->path);
free (g->last_error);
free (g->path);