Merge commit 'f30e1bdf97ae8b2b2918da585f887a4d3a23a347' into boehm-demers-weiser-gc
[bpt/guile.git] / libguile / coop-pthreads.c
index b1759f9..6415830 100644 (file)
@@ -31,7 +31,7 @@
 #include "libguile/eval.h"
 #include "libguile/async.h"
 #include "libguile/ports.h"
-#include "libguile/gc.h"
+#include "libguile/smob.h"
 
 #undef DEBUG
 
@@ -101,7 +101,8 @@ make_thread (SCM creation_protects)
 {
   SCM z;
   scm_copt_thread *t = scm_gc_malloc (sizeof(*t), "thread");
-  z = scm_cell (scm_tc16_thread, (scm_t_bits)t);
+
+  SCM_NEWSMOB (z, t);
   t->handle = z;
   t->result = creation_protects;
   t->base = NULL;
@@ -129,15 +130,6 @@ init_thread_creatant (SCM thread, SCM_STACKITEM *base)
   t->top = NULL;
 }
 
-static SCM
-thread_mark (SCM obj)
-{
-  scm_copt_thread *t = SCM_THREAD_DATA (obj);
-  scm_gc_mark (t->result);
-  scm_gc_mark (t->joining_threads);
-  return t->root->handle;
-}
-
 static int
 thread_print (SCM exp, SCM port, scm_print_state *pstate SCM_UNUSED)
 {
@@ -517,7 +509,7 @@ create_thread (scm_t_catch_body body, void *body_data,
 
     /* Allocate thread locals. */
     root = scm_make_root (scm_root->handle);
-    data = scm_malloc (sizeof (launch_data));
+    data = scm_gc_malloc (sizeof (launch_data));
 
     /* Make thread. */
     thread = make_thread (protects);
@@ -596,13 +588,6 @@ typedef struct scm_copt_mutex {
   SCM waiting;
 } scm_copt_mutex;
 
-static SCM
-mutex_mark (SCM mx)
-{
-  scm_copt_mutex *m = SCM_MUTEX_DATA (mx);
-  scm_gc_mark (m->owner);
-  return m->waiting;
-}
 
 SCM
 scm_make_mutex ()
@@ -826,13 +811,7 @@ scm_threads_init (SCM_STACKITEM *base)
   scm_gc_register_root (&all_threads);
   all_threads = scm_cons (cur_thread, SCM_EOL);
 
-  scm_set_smob_mark (scm_tc16_thread, thread_mark);
   scm_set_smob_print (scm_tc16_thread, thread_print);
-  scm_set_smob_free (scm_tc16_thread, thread_free);
-
-  scm_set_smob_mark (scm_tc16_mutex, mutex_mark);
-
-  scm_set_smob_mark (scm_tc16_condvar, cond_mark);
 }
 
 /*** Marking stacks */
@@ -855,83 +834,7 @@ scm_threads_init (SCM_STACKITEM *base)
 # define SCM_MARK_BACKING_STORE()
 #endif
 
-void
-scm_threads_mark_stacks (void)
-{
-  volatile SCM c;
-  for (c = all_threads; !scm_is_null (c); c = SCM_CDR (c))
-    {
-      scm_copt_thread *t = SCM_THREAD_DATA (SCM_CAR (c));
-      if (t->base == NULL)
-       {
-         /* Not fully initialized yet. */
-         continue;
-       }
-      if (t->top == NULL)
-       {
-         /* Active thread */
-         /* stack_len is long rather than sizet in order to guarantee
-            that &stack_len is long aligned */
-#if SCM_STACK_GROWS_UP
-         long stack_len = ((SCM_STACKITEM *) (&t) -
-                           (SCM_STACKITEM *) thread->base);
-         
-         /* Protect from the C stack.  This must be the first marking
-          * done because it provides information about what objects
-          * are "in-use" by the C code.   "in-use" objects are  those
-          * for which the information about length and base address must
-          * remain usable.   This requirement is stricter than a liveness
-          * requirement -- in particular, it constrains the implementation
-          * of scm_resizuve.
-          */
-         SCM_FLUSH_REGISTER_WINDOWS;
-         /* This assumes that all registers are saved into the jmp_buf */
-         setjmp (scm_save_regs_gc_mark);
-         scm_mark_locations ((SCM_STACKITEM *) scm_save_regs_gc_mark,
-                             ((size_t) sizeof scm_save_regs_gc_mark
-                              / sizeof (SCM_STACKITEM)));
-         
-         scm_mark_locations (((size_t) t->base,
-                              (sizet) stack_len));
-#else
-         long stack_len = ((SCM_STACKITEM *) t->base -
-                           (SCM_STACKITEM *) (&t));
-         
-         /* Protect from the C stack.  This must be the first marking
-          * done because it provides information about what objects
-          * are "in-use" by the C code.   "in-use" objects are  those
-          * for which the information about length and base address must
-          * remain usable.   This requirement is stricter than a liveness
-          * requirement -- in particular, it constrains the implementation
-          * of scm_resizuve.
-          */
-         SCM_FLUSH_REGISTER_WINDOWS;
-         /* This assumes that all registers are saved into the jmp_buf */
-         setjmp (scm_save_regs_gc_mark);
-         scm_mark_locations ((SCM_STACKITEM *) scm_save_regs_gc_mark,
-                             ((size_t) sizeof scm_save_regs_gc_mark
-                              / sizeof (SCM_STACKITEM)));
-         
-         scm_mark_locations ((SCM_STACKITEM *) &t,
-                             stack_len);
-#endif
-       }
-      else
-       {
-         /* Suspended thread */
-#if SCM_STACK_GROWS_UP
-         long stack_len = t->top - t->base;
-         scm_mark_locations (t->base, stack_len);
-#else
-         long stack_len = t->base - t->top;
-         scm_mark_locations (t->top, stack_len);
-#endif
-         scm_mark_locations ((SCM_STACKITEM *) t->regs,
-                             ((size_t) sizeof(t->regs)
-                              / sizeof (SCM_STACKITEM)));
-       }
-    }
-}
+
 
 /*** Select */