mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-04-30 11:50:28 +02:00
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!
This commit is contained in:
parent
2a3db25e28
commit
b34608813d
1 changed files with 7 additions and 12 deletions
|
@ -52,6 +52,7 @@
|
||||||
|
|
||||||
|
|
||||||
static SCM symbols;
|
static SCM symbols;
|
||||||
|
static scm_i_pthread_mutex_t symbols_lock = SCM_I_PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
|
||||||
#ifdef GUILE_DEBUG
|
#ifdef GUILE_DEBUG
|
||||||
SCM_DEFINE (scm_sys_symbols, "%symbols", 0, 0, 0,
|
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 = name;
|
||||||
data.string_hash = raw_hash;
|
data.string_hash = raw_hash;
|
||||||
|
|
||||||
/* Strictly speaking, we should take a lock here. But instead we rely
|
scm_i_pthread_mutex_lock (&symbols_lock);
|
||||||
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. */
|
|
||||||
handle = scm_hash_fn_get_handle_by_hash (symbols, raw_hash,
|
handle = scm_hash_fn_get_handle_by_hash (symbols, raw_hash,
|
||||||
string_lookup_predicate_fn,
|
string_lookup_predicate_fn,
|
||||||
&data);
|
&data);
|
||||||
|
scm_i_pthread_mutex_unlock (&symbols_lock);
|
||||||
|
|
||||||
if (scm_is_true (handle))
|
if (scm_is_true (handle))
|
||||||
return SCM_CAR (handle);
|
return SCM_CAR (handle);
|
||||||
|
@ -151,13 +150,11 @@ lookup_interned_latin1_symbol (const char *str, size_t len,
|
||||||
data.len = len;
|
data.len = len;
|
||||||
data.string_hash = raw_hash;
|
data.string_hash = raw_hash;
|
||||||
|
|
||||||
/* Strictly speaking, we should take a lock here. But instead we rely
|
scm_i_pthread_mutex_lock (&symbols_lock);
|
||||||
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. */
|
|
||||||
handle = scm_hash_fn_get_handle_by_hash (symbols, raw_hash,
|
handle = scm_hash_fn_get_handle_by_hash (symbols, raw_hash,
|
||||||
latin1_lookup_predicate_fn,
|
latin1_lookup_predicate_fn,
|
||||||
&data);
|
&data);
|
||||||
|
scm_i_pthread_mutex_unlock (&symbols_lock);
|
||||||
|
|
||||||
if (scm_is_true (handle))
|
if (scm_is_true (handle))
|
||||||
return SCM_CAR (handle);
|
return SCM_CAR (handle);
|
||||||
|
@ -187,8 +184,6 @@ symbol_lookup_assoc_fn (SCM obj, SCM alist, void *closure)
|
||||||
return SCM_BOOL_F;
|
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
|
/* Intern SYMBOL, an uninterned symbol. Might return a different
|
||||||
symbol, if another one was interned at the same time. */
|
symbol, if another one was interned at the same time. */
|
||||||
static SCM
|
static SCM
|
||||||
|
@ -196,12 +191,12 @@ intern_symbol (SCM symbol)
|
||||||
{
|
{
|
||||||
SCM handle;
|
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,
|
handle = scm_hash_fn_create_handle_x (symbols, symbol, SCM_UNDEFINED,
|
||||||
symbol_lookup_hash_fn,
|
symbol_lookup_hash_fn,
|
||||||
symbol_lookup_assoc_fn,
|
symbol_lookup_assoc_fn,
|
||||||
NULL);
|
NULL);
|
||||||
scm_i_pthread_mutex_unlock (&intern_lock);
|
scm_i_pthread_mutex_unlock (&symbols_lock);
|
||||||
|
|
||||||
return SCM_CAR (handle);
|
return SCM_CAR (handle);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue