diff options
author | Andy Wingo <wingo@pobox.com> | 2010-08-28 11:57:51 -0700 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2010-08-28 11:57:51 -0700 |
commit | f5e854388b4d96cbfa65b95a689c50e5e2d1a2b6 (patch) | |
tree | 3fdce59ebd2beb449d42ff8bfad340efdf1f9435 | |
parent | 35b6730879bd63a46270abce833a912624f2b2e3 (diff) | |
download | guile-f5e854388b4d96cbfa65b95a689c50e5e2d1a2b6.tar.gz |
threadsafe object properties
* libguile/objprop.c: Add locking around the properties weak hash, to
avoid corrupting the whash.
-rw-r--r-- | libguile/objprop.c | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/libguile/objprop.c b/libguile/objprop.c index 39fcfb5ca..dfa849441 100644 --- a/libguile/objprop.c +++ b/libguile/objprop.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1995,1996, 2000, 2001, 2003, 2006, 2008, 2009 Free Software Foundation, Inc. +/* Copyright (C) 1995,1996, 2000, 2001, 2003, 2006, 2008, 2009, 2010 Free Software Foundation, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -36,13 +36,20 @@ */ static SCM object_whash; +static scm_i_pthread_mutex_t whash_mutex = SCM_I_PTHREAD_MUTEX_INITIALIZER; SCM_DEFINE (scm_object_properties, "object-properties", 1, 0, 0, (SCM obj), "Return @var{obj}'s property list.") #define FUNC_NAME s_scm_object_properties { - return scm_hashq_ref (object_whash, obj, SCM_EOL); + SCM ret; + + scm_i_pthread_mutex_lock (&whash_mutex); + ret = scm_hashq_ref (object_whash, obj, SCM_EOL); + scm_i_pthread_mutex_unlock (&whash_mutex); + + return ret; } #undef FUNC_NAME @@ -52,8 +59,13 @@ SCM_DEFINE (scm_set_object_properties_x, "set-object-properties!", 2, 0, 0, "Set @var{obj}'s property list to @var{alist}.") #define FUNC_NAME s_scm_set_object_properties_x { - SCM handle = scm_hashq_create_handle_x (object_whash, obj, alist); + SCM handle; + + scm_i_pthread_mutex_lock (&whash_mutex); + handle = scm_hashq_create_handle_x (object_whash, obj, alist); SCM_SETCDR (handle, alist); + scm_i_pthread_mutex_unlock (&whash_mutex); + return alist; } #undef FUNC_NAME @@ -77,8 +89,9 @@ SCM_DEFINE (scm_set_object_property_x, "set-object-property!", 3, 0, 0, { SCM h; SCM assoc; + + scm_i_pthread_mutex_lock (&whash_mutex); h = scm_hashq_create_handle_x (object_whash, obj, SCM_EOL); - SCM_CRITICAL_SECTION_START; assoc = scm_assq (key, SCM_CDR (h)); if (SCM_NIMP (assoc)) SCM_SETCDR (assoc, value); @@ -87,7 +100,8 @@ SCM_DEFINE (scm_set_object_property_x, "set-object-property!", 3, 0, 0, assoc = scm_acons (key, value, SCM_CDR (h)); SCM_SETCDR (h, assoc); } - SCM_CRITICAL_SECTION_END; + scm_i_pthread_mutex_unlock (&whash_mutex); + return value; } #undef FUNC_NAME |