diff --git a/Smake b/Smake index f6ab964..8af2c10 100644 --- a/Smake +++ b/Smake @@ -37,6 +37,7 @@ GNULIB_MODULES = \ intprops \ inttostr \ localcharset \ + lock \ mbchar \ memcasecmp \ memchr \ diff --git a/src/data/value-labels.c b/src/data/value-labels.c index 9f6113b..58e5b8c 100644 --- a/src/data/value-labels.c +++ b/src/data/value-labels.c @@ -27,6 +27,7 @@ #include #include #include +#include #include "xalloc.h" @@ -413,6 +414,7 @@ static hsh_free_func free_atom; /* Hash table of atoms. */ static struct hsh_table *atoms; +gl_once_define (static, atom_once); static void destroy_atoms (void) @@ -420,6 +422,14 @@ destroy_atoms (void) hsh_destroy (atoms); } +static void +initialize_atom_hash (void) +{ + atoms = hsh_create (8, compare_atoms, hash_atom, free_atom, NULL); + atexit (destroy_atoms); +} + + /* Creates and returns an atom for STRING. */ static struct atom * atom_create (const char *string) @@ -429,11 +439,7 @@ atom_create (const char *string) assert (string != NULL); - if (atoms == NULL) - { - atoms = hsh_create (8, compare_atoms, hash_atom, free_atom, NULL); - atexit (destroy_atoms); - } + gl_once (atom_once, initialize_atom_hash); a.string = (char *) string; app = hsh_probe (atoms, &a); diff --git a/src/libpspp/pool.c b/src/libpspp/pool.c index 88d3535..17f8c07 100644 --- a/src/libpspp/pool.c +++ b/src/libpspp/pool.c @@ -19,6 +19,7 @@ #include #include #include +#include #include "message.h" #include "str.h" @@ -121,6 +122,7 @@ union align /* Serial number used to keep track of gizmos for mark/release. */ static long serial = 0; +gl_lock_define_initialized (static, serial_mutex); /* Prototypes. */ static void add_gizmo (struct pool *, struct pool_gizmo *); @@ -898,7 +900,9 @@ add_gizmo (struct pool *pool, struct pool_gizmo *gizmo) pool->gizmos->prev = gizmo; pool->gizmos = gizmo; + glthread_lock_lock (&serial_mutex); gizmo->serial = serial++; + glthread_lock_unlock (&serial_mutex); check_gizmo (pool, gizmo); }