diff options
author | Neil Jerram <neil@ossau.uklinux.net> | 2009-03-25 22:50:46 +0000 |
---|---|---|
committer | Neil Jerram <neil@ossau.uklinux.net> | 2009-03-27 21:38:07 +0000 |
commit | 9ec74a6a4e3d5b1d4b9eb23d1045aad2b0536e05 (patch) | |
tree | b51fd02b83fa92b8da310fb6cbcaa27386d32648 /libguile/hashtab.h | |
parent | 10b11bab3317f72f74b59c1b5becf731215ae2f4 (diff) | |
download | guile-wip-nj-locks-nc.tar.gz |
Allow non-weak hash tables to be automatically thread-safewip-nj-locks-nc
This patch allows a fat mutex to be associated with a hash table.
When a hash table has an associated mutex, that mutex will be
automatically locked and unlocked around all operations (include
lookups) on the hash table's internal data.
* libguile/hashtab.c (make_hash_table): Init mutex field to #f.
(hashtable_mark): New function.
(scm_hash_fn_get_handle, scm_hash_fn_create_handle_x,
scm_hash_fn_remove_x, scm_hash_clear_x, scm_internal_hash_fold,
scm_internal_hash_for_each_handle): If the hash table has a mutex,
lock and unlock it around all accessing of the hash table's
internals.
(scm_hash_use_mutex_x): New function.
(scm_hashtab_prehistory): Use hashtable_mark as hash table mark
function.
* libguile/hashtab.h (SCM_HASHTABLE_MUTEX, SCM_SET_HASHTABLE_MUTEX,
scm_hash_use_mutex_x): New declarations.
(scm_t_hashtable): New mutex field.
Diffstat (limited to 'libguile/hashtab.h')
-rw-r--r-- | libguile/hashtab.h | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/libguile/hashtab.h b/libguile/hashtab.h index 3eca04cb9..79cb30cf8 100644 --- a/libguile/hashtab.h +++ b/libguile/hashtab.h @@ -58,6 +58,8 @@ SCM_API scm_t_bits scm_tc16_hashtable; #define SCM_HASHTABLE_DECREMENT(x) (SCM_HASHTABLE_N_ITEMS(x)--) #define SCM_HASHTABLE_UPPER(x) (SCM_HASHTABLE (x)->upper) #define SCM_HASHTABLE_LOWER(x) (SCM_HASHTABLE (x)->lower) +#define SCM_HASHTABLE_MUTEX(x) (SCM_HASHTABLE (x)->mutex) +#define SCM_SET_HASHTABLE_MUTEX(x, m) (SCM_HASHTABLE (x)->mutex = m) #define SCM_HASHTABLE_N_BUCKETS(h) \ SCM_SIMPLE_VECTOR_LENGTH (SCM_HASHTABLE_VECTOR (h)) @@ -74,6 +76,7 @@ typedef struct scm_t_hashtable { int size_index; /* index into hashtable_size */ int min_size_index; /* minimum size_index */ unsigned long (*hash_fn) (); /* for rehashing after a GC. */ + SCM mutex; /* mutex for thread safety */ } scm_t_hashtable; @@ -133,6 +136,7 @@ SCM_API SCM scm_hash_fold (SCM proc, SCM init, SCM hash); SCM_API SCM scm_hash_for_each (SCM proc, SCM hash); SCM_API SCM scm_hash_for_each_handle (SCM proc, SCM hash); SCM_API SCM scm_hash_map_to_list (SCM proc, SCM hash); +SCM_API SCM scm_hash_use_mutex_x (SCM hash, SCM mutex); SCM_API void scm_hashtab_prehistory (void); SCM_API void scm_init_hashtab (void); |