summaryrefslogtreecommitdiff
path: root/libguile/symbols.c
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2011-05-23 22:24:27 +0200
committerAndy Wingo <wingo@pobox.com>2011-05-23 22:24:27 +0200
commitb34608813de5fce7f8caee63bdbaeab445eb366e (patch)
tree380e2b4b7bb976cd51b49cf81725b1c0039445bf /libguile/symbols.c
parent2a3db25e283a6b8e30d9761546605e7cae757c67 (diff)
downloadguile-b34608813de5fce7f8caee63bdbaeab445eb366e.tar.gz
really threadsafe access to symbol table
* libguile/symbols.c (symbols_lock): Rename from intern_lock. (lookup_interned_symbol, lookup_interned_latin1_symbol): Instead of faith-based programming, just use the mutex. Though I haven't seen this break, Ken is right!
Diffstat (limited to 'libguile/symbols.c')
-rw-r--r--libguile/symbols.c19
1 files changed, 7 insertions, 12 deletions
diff --git a/libguile/symbols.c b/libguile/symbols.c
index 2a1b46dce..59aca002e 100644
--- a/libguile/symbols.c
+++ b/libguile/symbols.c
@@ -52,6 +52,7 @@
static SCM symbols;
+static scm_i_pthread_mutex_t symbols_lock = SCM_I_PTHREAD_MUTEX_INITIALIZER;
#ifdef GUILE_DEBUG
SCM_DEFINE (scm_sys_symbols, "%symbols", 0, 0, 0,
@@ -108,13 +109,11 @@ lookup_interned_symbol (SCM name, unsigned long raw_hash)
data.string = name;
data.string_hash = raw_hash;
- /* Strictly speaking, we should take a lock here. But instead we rely
- on the fact that if this fails, we do take the lock on the
- intern_symbol path; and since nothing deletes from the hash table
- except GC, we should be OK. */
+ scm_i_pthread_mutex_lock (&symbols_lock);
handle = scm_hash_fn_get_handle_by_hash (symbols, raw_hash,
string_lookup_predicate_fn,
&data);
+ scm_i_pthread_mutex_unlock (&symbols_lock);
if (scm_is_true (handle))
return SCM_CAR (handle);
@@ -151,13 +150,11 @@ lookup_interned_latin1_symbol (const char *str, size_t len,
data.len = len;
data.string_hash = raw_hash;
- /* Strictly speaking, we should take a lock here. But instead we rely
- on the fact that if this fails, we do take the lock on the
- intern_symbol path; and since nothing deletes from the hash table
- except GC, we should be OK. */
+ scm_i_pthread_mutex_lock (&symbols_lock);
handle = scm_hash_fn_get_handle_by_hash (symbols, raw_hash,
latin1_lookup_predicate_fn,
&data);
+ scm_i_pthread_mutex_unlock (&symbols_lock);
if (scm_is_true (handle))
return SCM_CAR (handle);
@@ -187,8 +184,6 @@ symbol_lookup_assoc_fn (SCM obj, SCM alist, void *closure)
return SCM_BOOL_F;
}
-static scm_i_pthread_mutex_t intern_lock = SCM_I_PTHREAD_MUTEX_INITIALIZER;
-
/* Intern SYMBOL, an uninterned symbol. Might return a different
symbol, if another one was interned at the same time. */
static SCM
@@ -196,12 +191,12 @@ intern_symbol (SCM symbol)
{
SCM handle;
- scm_i_pthread_mutex_lock (&intern_lock);
+ scm_i_pthread_mutex_lock (&symbols_lock);
handle = scm_hash_fn_create_handle_x (symbols, symbol, SCM_UNDEFINED,
symbol_lookup_hash_fn,
symbol_lookup_assoc_fn,
NULL);
- scm_i_pthread_mutex_unlock (&intern_lock);
+ scm_i_pthread_mutex_unlock (&symbols_lock);
return SCM_CAR (handle);
}