summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2011-06-16 19:35:14 +0200
committerAndy Wingo <wingo@pobox.com>2011-06-16 19:39:58 +0200
commit0b77014f0c7d53b8bdbc7059c92f526560e1cacd (patch)
tree66f00f9f8d84ef61b96e839aa1442d6ff59bc1cf
parent2dd49486445c18f047dd2b81e9d9f49dc1b2c41b (diff)
downloadguile-0b77014f0c7d53b8bdbc7059c92f526560e1cacd.tar.gz
fix initial values of reallocated fluids
* libguile/threads.h: * libguile/threads.c (scm_i_reset_fluid): New internal function, resets the binding of a fluid for all threads. Needed for fluid GC. * libguile/fluids.c (new_fluid): Call scm_i_reset_fluid here.
-rw-r--r--libguile/fluids.c5
-rw-r--r--libguile/threads.c18
-rw-r--r--libguile/threads.h1
3 files changed, 24 insertions, 0 deletions
diff --git a/libguile/fluids.c b/libguile/fluids.c
index f42c0a484..67efd9f6a 100644
--- a/libguile/fluids.c
+++ b/libguile/fluids.c
@@ -163,6 +163,11 @@ new_fluid ()
SCM2PTR (fluid));
scm_dynwind_end ();
+
+ /* Now null out values. We could (and probably should) do this when
+ the fluid is collected instead of now. */
+ scm_i_reset_fluid (n, SCM_BOOL_F);
+
return fluid;
}
diff --git a/libguile/threads.c b/libguile/threads.c
index 64807f8c0..97d9f6497 100644
--- a/libguile/threads.c
+++ b/libguile/threads.c
@@ -484,6 +484,24 @@ static int thread_count;
static SCM scm_i_default_dynamic_state;
+/* Run when a fluid is collected. */
+void
+scm_i_reset_fluid (size_t n, SCM val)
+{
+ scm_i_thread *t;
+
+ scm_i_pthread_mutex_lock (&thread_admin_mutex);
+ for (t = all_threads; t; t = t->next_thread)
+ if (SCM_I_DYNAMIC_STATE_P (t->dynamic_state))
+ {
+ SCM v = SCM_I_DYNAMIC_STATE_FLUIDS (t->dynamic_state);
+
+ if (n < SCM_SIMPLE_VECTOR_LENGTH (v))
+ SCM_SIMPLE_VECTOR_SET (v, n, val);
+ }
+ scm_i_pthread_mutex_unlock (&thread_admin_mutex);
+}
+
/* Perform first stage of thread initialisation, in non-guile mode.
*/
static void
diff --git a/libguile/threads.h b/libguile/threads.h
index 609262a19..edecad819 100644
--- a/libguile/threads.h
+++ b/libguile/threads.h
@@ -136,6 +136,7 @@ SCM_API SCM scm_spawn_thread (scm_t_catch_body body, void *body_data,
SCM_API void *scm_without_guile (void *(*func)(void *), void *data);
SCM_API void *scm_with_guile (void *(*func)(void *), void *data);
+SCM_INTERNAL void scm_i_reset_fluid (size_t, SCM);
SCM_INTERNAL void scm_threads_prehistory (void *);
SCM_INTERNAL void scm_init_threads (void);
SCM_INTERNAL void scm_init_thread_procs (void);