* If you do not wish that, delete this exception notice. */
\f
-/* $Id: coop.c,v 1.15 1998-11-19 08:15:22 mdj Exp $ */
+/* $Id: coop.c,v 1.16 1999-12-19 18:24:12 gjb Exp $ */
/* Cooperative thread library, based on QuickThreads */
/* Queue access functions. */
-#ifdef __STDC__
static void
coop_qinit (coop_q_t *q)
-#else
-static void
-coop_qinit (q)
- coop_q_t *q;
-#endif
{
q->t.next = q->tail = &q->t;
}
-#ifdef __STDC__
coop_t *
coop_qget (coop_q_t *q)
-#else
-coop_t *
-coop_qget (q)
- coop_q_t *q;
-#endif
{
coop_t *t;
}
-#ifdef __STDC__
void
coop_qput (coop_q_t *q, coop_t *t)
-#else
-void
-coop_qput (q, t)
- coop_q_t *q;
- coop_t *t;
-#endif
{
q->tail->next = t;
t->next = &q->t;
q->tail = t;
}
-#ifdef __STDC__
static void
coop_all_qput (coop_q_t *q, coop_t *t)
-#else
-static void
-coop_all_qput (q, t)
- coop_q_t *q;
- coop_t *t;
-#endif
{
if (q->t.all_next)
q->t.all_next->all_prev = t;
q->t.all_next = t;
}
-#ifdef __STDC__
static void
coop_all_qremove (coop_q_t *q, coop_t *t)
-#else
-static void
-coop_all_qremove (q, t)
- coop_q_t *q;
- coop_t *t;
-#endif
{
if (t->all_prev)
t->all_prev->all_next = t->all_next;
static void *coop_yieldhelp (qt_t *sp, void *old, void *blockq);
-#ifdef __STDC__
void
coop_init()
-#else
-void
-coop_init()
-#endif
{
coop_qinit (&coop_global_runq);
coop_qinit (&coop_global_sleepq);
return NULL. */
#ifndef GUILE_ISELECT
-#ifdef __STDC__
coop_t *
coop_next_runnable_thread()
-#else
-coop_t *
-coop_next_runnable_thread()
-#endif
{
int sleepers;
coop_t *t;
}
#endif
-#ifdef __STDC__
-void
-coop_start()
-#else
void
coop_start()
-#endif
{
coop_t *next;
}
-#ifdef __STDC__
static void *
coop_starthelp (qt_t *old, void *ignore0, void *ignore1)
-#else
-static void *
-coop_starthelp (old, ignore0, ignore1)
- qt_t *old;
- void *ignore0;
- void *ignore1;
-#endif
{
coop_global_main.sp = old;
coop_global_main.joining = NULL;
return NULL; /* not used, but keeps compiler happy */
}
-#ifdef __STDC__
int
coop_mutex_init (coop_m *m)
-#else
-int
-coop_mutex_init (m)
- coop_m *m;
-#endif
{
m->owner = NULL;
coop_qinit(&(m->waiting));
return 0;
}
-#ifdef __STDC__
int
coop_mutex_lock (coop_m *m)
-#else
-int
-coop_mutex_lock ()
- coop_m *m;
-#endif
{
if (m->owner == NULL)
{
}
-#ifdef __STDC__
int
coop_mutex_unlock (coop_m *m)
-#else
-int
-coop_mutex_unlock (m)
- coop_m *m;
-#endif
{
coop_t *old, *newthread;
}
-#ifdef __STDC__
int
coop_mutex_destroy (coop_m *m)
-#else
-int
-coop_mutex_destroy (m)
- coop_m *m;
-#endif
{
return 0;
}
-#ifdef __STDC__
int
coop_condition_variable_init (coop_c *c)
-#else
-int
-coop_condition_variable_init (c)
- coop_c *c;
-#endif
{
coop_qinit(&(c->waiting));
return 0;
}
-#ifdef __STDC__
int
coop_condition_variable_wait_mutex (coop_c *c, coop_m *m)
-#else
-int
-coop_condition_variable_wait_mutex (c, m)
- coop_c *c;
- coop_m *m;
-#endif
{
coop_t *old, *newthread;
}
-#ifdef __STDC__
int
coop_condition_variable_signal (coop_c *c)
-#else
-int
-coop_condition_variable_signal (c)
- coop_c *c;
-#endif
{
coop_t *newthread;
}
-#ifdef __STDC__
int
coop_condition_variable_destroy (coop_c *c)
-#else
-int
-coop_condition_variable_destroy (c)
- coop_c *c;
-#endif
{
return 0;
}
-#ifdef __STDC__
coop_t *
coop_create (coop_userf_t *f, void *pu)
-#else
-coop_t *
-coop_create (f, pu)
- coop_userf_t *f;
- void *pu;
-#endif
{
coop_t *t;
void *sto;
}
-#ifdef __STDC__
static void
coop_only (void *pu, void *pt, qt_userf_t *f)
-#else
-static void
-coop_only (pu. pt, f)
- void *pu,
- void *pt,
- qt_userf_t *f;
-#endif
{
coop_global_curr = (coop_t *)pt;
(*(coop_userf_t *)f)(pu);
}
-#ifdef __STDC__
-void
-coop_abort ()
-#else
void
coop_abort ()
-#endif
{
coop_t *old, *newthread;
}
-#ifdef __STDC__
static void *
coop_aborthelp (qt_t *sp, void *old, void *null)
-#else
-static void *
-coop_aborthelp (sp, old, null)
- qt_t *sp;
- void *old;
- void *null;
-#endif
{
coop_t *oldthread = (coop_t *) old;
}
-#ifdef __STDC__
void
coop_join(coop_t *t)
-#else
-void
-coop_join()
- coop_t *t;
-#endif
{
coop_t *old, *newthread;
QT_BLOCK (coop_yieldhelp, old, (coop_q_t *) t->joining, newthread->sp);
}
-#ifdef __STDC__
-void
-coop_yield()
-#else
void
coop_yield()
-#endif
{
coop_t *old = NULL;
coop_t *newthread;
}
-#ifdef __STDC__
static void *
coop_yieldhelp (qt_t *sp, void *old, void *blockq)
-#else
-static void *
-coop_yieldhelp (sp, old, blockq)
- qt_t *sp;
- void *old;
- void *blockq;
-#endif
{
((coop_t *)old)->sp = sp;
coop_qput ((coop_q_t *)blockq, (coop_t *)old);
/* Key to thread specific data */
pthread_key_t info_key;
-#ifdef __STDC__
size_t
scm_threads_free_thread (SCM t)
-#else
-size_t
-scm_threads_free_thread (t)
- SCM t;
-#endif
{
scm_must_free (SCM_THREAD_DATA (t));
return sizeof (pthread_t);
}
-#ifdef __STDC__
size_t
scm_threads_free_mutex (SCM m)
-#else
-size_t
-scm_threads_free_mutex (m)
- SCM m;
-#endif
{
pthread_mutex_destroy (SCM_MUTEX_DATA (m));
scm_must_free (SCM_MUTEX_DATA (m));
return sizeof (pthread_mutex_t);
}
-#ifdef __STDC__
size_t
scm_threads_free_condvar (SCM c)
-#else
-size_t
-scm_threads_free_condvar (c)
- SCM c;
-#endif
{
pthread_cond_destroy (SCM_CONDVAR_DATA (c));
scm_must_free (SCM_CONDVAR_DATA (c));
/* cleanup for info structure
*/
-#ifdef __STDC__
static void
scm_pthread_delete_info (void *ptr)
-#else
-static void
-scm_pthread_delete_info (ptr)
- void *ptr;
-#endif
{
scm_pthread_info *info = (scm_pthread_info *) ptr;
info->q.blink->flink = info->q.flink;
scm_must_free ((char *) info);
}
-#ifdef __STDC__
void
scm_threads_init (SCM_STACKITEM *i)
-#else
-void
-scm_threads_init (i)
- SCM_STACKITEM *i;
-#endif
{
/*
* each info structure is made thread-specific, so that the cleanup
}
}
-#ifdef __STDC__
void
scm_threads_mark_stacks ()
-#else
-void
-scm_threads_mark_stacks ()
-#endif
{
scm_pthread_info *info;
pthread_t thread;
}
}
-#ifdef __STDC__
void *
launch_thread (void *p)
-#else
-void *
-launch_thread (p)
- void *p;
-#endif
{
/* The thread object will be GC protected by being a member of the
list given as argument to launch_thread. It will be marked
return NULL;
}
-#ifdef __STDC__
SCM
scm_call_with_new_thread (SCM argl)
-#else
-SCM
-scm_call_with_new_thread (argl)
- SCM argl;
-#endif
{
SCM thread;
return thread;
}
-#ifdef __STDC__
SCM
scm_join_thread (SCM t)
-#else
-SCM
-scm_join_thread (t)
- SCM t;
-#endif
{
void *value;
pthread_join (SCM_THREAD_DATA (t), &value);
return SCM_BOOL_T;
}
-#ifdef __STDC__
SCM
scm_yield ()
-#else
-SCM
-scm_yield ()
-#endif
{
pthread_yield ();
return SCM_BOOL_T;
}
-#ifdef __STDC__
SCM
scm_make_mutex ()
-#else
-SCM
-scm_make_mutex ()
-#endif
{
SCM m;
pthread_mutex_t *data = (pthread_mutex_t *) scm_must_malloc (sizeof (pthread_mutex_t), "mutex");
return m;
}
-#ifdef __STDC__
SCM
scm_lock_mutex (SCM m)
-#else
-SCM
-scm_lock_mutex (m)
- SCM m;
-#endif
{
SCM_ASSERT (SCM_MUTEXP (m), m, SCM_ARG1, s_lock_mutex);
pthread_mutex_lock (SCM_MUTEX_DATA (m));
return SCM_BOOL_T;
}
-#ifdef __STDC__
SCM
scm_unlock_mutex (SCM m)
-#else
-SCM
-scm_unlock_mutex (m)
- SCM m;
-#endif
{
SCM_ASSERT (SCM_MUTEXP (m), m, SCM_ARG1, s_unlock_mutex);
pthread_mutex_unlock (SCM_MUTEX_DATA (m));
return SCM_BOOL_T;
}
-#ifdef __STDC__
SCM
scm_make_condition_variable ()
-#else
-SCM
-scm_make_condition_variable ()
-#endif
{
SCM c;
pthread_cond_t *data = (pthread_cond_t *) scm_must_malloc (sizeof (pthread_cond_t), "condvar");
return c;
}
-#ifdef __STDC__
SCM
scm_wait_condition_variable (SCM c, SCM m)
-#else
-SCM
-scm_wait_condition_variable (c, m)
- SCM c;
- SCM m;
-#endif
{
SCM_ASSERT (SCM_CONDVARP (c),
c,
return SCM_BOOL_T;
}
-#ifdef __STDC__
SCM
scm_signal_condition_variable (SCM c)
-#else
-SCM
-scm_signal_condition_variable (c)
- SCM c;
-#endif
{
SCM_ASSERT (SCM_CONDVARP (c),
c,