#include "libguile/eval.h"
#include "libguile/async.h"
#include "libguile/ports.h"
-#include "libguile/gc.h"
+#include "libguile/smob.h"
#undef DEBUG
{
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;
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)
{
/* 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);
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 ()
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 */
# 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 */