make static hash table access thread-safe in foreign.c
authorAndy Wingo <wingo@pobox.com>
Thu, 10 Feb 2011 20:06:55 +0000 (21:06 +0100)
committerAndy Wingo <wingo@pobox.com>
Thu, 10 Feb 2011 22:16:51 +0000 (23:16 +0100)
* libguile/foreign.c (register_weak_reference): Wrap static hash table
  access in a mutex.

libguile/foreign.c

index c546c79..6f008e7 100644 (file)
@@ -30,6 +30,7 @@
 #include "libguile/_scm.h"
 #include "libguile/bytevectors.h"
 #include "libguile/instructions.h"
+#include "libguile/threads.h"
 #include "libguile/foreign.h"
 
 \f
@@ -86,11 +87,15 @@ static SCM cif_to_procedure (SCM cif, SCM func_ptr);
 
 
 static SCM pointer_weak_refs = SCM_BOOL_F;
+static scm_i_pthread_mutex_t weak_refs_lock = SCM_I_PTHREAD_MUTEX_INITIALIZER;
+
 
 static void
 register_weak_reference (SCM from, SCM to)
 {
+  scm_i_pthread_mutex_lock (&weak_refs_lock);
   scm_hashq_set_x (pointer_weak_refs, from, to);
+  scm_i_pthread_mutex_unlock (&weak_refs_lock);
 }
 
 static void